Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By Sivaji_Ganesh_Jojodae on
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
the performance difference
the performance difference should be tiny ( also see http://drupal.org/node/249751 ). probably just habit.
It's simply a coding habit.
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. I also stream on Twitch in my spare time.
according to
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.
Drupal Benchmarks?
I'd be interested in knowing if anyone has the patience to convert all
print
's toecho
's and do some benchmarking ;)Some softwares can do this by
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 ;)
Performance difference is
Performance difference is negligible in any real world application.
But isn't ANY performance
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?
Bull!
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.