Why do some well-known programs always use printing

I read somewhere, I don’t remember where now, echo is a more efficient way to output data, then print .

Why do many well-known software packages and frameworks, such as WordPress and Drupal, also print? Is there any special reason, or just a habit?

+8
php drupal wordpress
source share
4 answers

In all actions, Echo and Print differ depending on how they are structured. Printing returns a value similar to a normal function. But, despite the widespread belief, Print is not a function, since we can see that it does not require brackets to work (Do not confuse with Printf). Print and Echo are actually called language constructs, although this does not mean that we cannot force Print to act as a function.

Here you can find an additional link:

http://www.learnphponline.com/php-basics/php-echo-vs-print

Not quite complete. Printing can be used as part of complex designs such as

 ($b) ? print "True" : print "False"; 

whereas Echo cannot. Also, if you want to use the error output (@print "Test";), you cannot use the echo. Otherwise, good information.

+7
source share

In PHP docs, nothing exists to support this claim. However, the key difference between the two is that echo does not return a value and print does. Therefore, one could argue that echo is more efficient.

Check out PHP Benchmark for more information on echo vs print and other interesting comparisons.

In the end, such things come down to personal convention. Whatever efficiency obtained by using echo more print , it is more than likely trivial with respect to other areas of the code.

+5
source share

In performance tests, I did not see a speed difference between print and echo in PHP, so they are interchangeable. This is actually a personal preference. In the wild, I saw how strictly PHP programmers adhere to echo , and multilingual programmers use it (if it's a phrase).

0
source share

Because you read these things on blogs that like to talk about micro-optimization. You should avoid premature optimization at all costs, because it is not worth the effort => You should make a famous quote from Google http://en.wikipedia.org/wiki/Tony_Hoare . You should fight your low hanging fruit when you have performance issues and stop wasting time reading these blogs. PHP creator gave a couple of presentations on how to do this => http://www.archive.org/details/simple_is_hard

This video is pretty old by now, but still very good if you ask me.

0
source share

All Articles