I wonder why drupal developer are using print in all the output statement instead of echo ? please have a look at this link http://www.learnphponline.com/php-basics/php-echo-vs-print it clearly says that echo is better because it doesnt return any value.Is there any specific reason for using print ?

Comments

wiml’s picture

the performance difference should be tiny ( also see http://drupal.org/node/249751 ). probably just habit.

TapSkill’s picture

It's simply a coding habit. You can use echo or print, it makes very little difference. I use print whenever I'm using code that returns a value. Otherwise, I risk the code not working. I've noticed a lot of Wordpress theme designers don't understand this and use echo for almost everything. Print is better for functionality, echo is better for performance.

---
I have created and maintained countless Drupal-powered sites and have made heavy modifications to modules on a site-by-site basis. I am an illustrator, a game developer, and a web developer.

GrimSage’s picture

according to http://www.phpbench.com/ there is actually a difference
Its around 12%-20% faster using echo compare to print when there is no $ symbol in the printing string. And around 40-80% faster if there is an $ symbol used in a printing string! This really demonstrate the differences between the keyword $ symbol used in PHP.

andrewsuth’s picture

I'd be interested in knowing if anyone has the patience to convert all print's to echo's and do some benchmarking ;)

beeleg’s picture

Some softwares can do this by replacing 'print' with 'echo' such as the Emeditor I'm using. Just run and wait to have it done ;)

Ildar Samit’s picture

Performance difference is negligible in any real world application.

Anonymous’s picture

But isn't ANY performance improvement a good thing? Can anyone provide an example where a performance improvement, however slight, can be a negative thing?

RichardLynch’s picture

Those benchmarks are just plain wrong.

This dead horse has been beaten up all over the Internet for years.

Bottom Line:

There is no measurable difference between echo and print that's going to matter for any reasonable online application in CURRENT PHP codebase.

Google more, read more, and get CURRENT benchmarks.