Why? Because in the first two examples PHP is having to allocate memory for multiple strings and then go through the (relatively) expensive process of “sticking” them together again. If you just declare a string over multiple lines you are avoiding that overhead. You have to be careful to make code readable if you do this but I’ve never had any problems with it.
Does this mean that multi-line echo statements are are better written as:
Just remember one simple rule: not a single syntax issue have any performance importance. You can use any syntax you wish and never worry about performance.
So, I am totally agree with hash - it won’t make any significant difference.
Also bear in mind that these coding tips aren’t treasure of wisdom.
Some of them obsoleted and some of them should be titled “Coding standards” and separated from the tips and some of them just not a truth.
That topic badly need to be edited and sorted out.
Im not too deep into how the exact inner workings of PHP and output to client works. Thus “transmission” might have been a bad choice of word…
In my book, every echo/print statement results in some data being sent somewhere.
Keeping the data on the PHP side, until all output is ready, will result in fewer connections/streams/transmissions,… or what its called…
I tried to do a little digging on the subject, but didnt really find anything usefull… perhaps you have some useful links/topics I could have a look at?
Honestly, if your worrying about whether calling echo or print once or multiple times is going to affect efficiency you need to step back and get your priorities in order. For me it comes down what is more readable. If using several calls to echo is more readable then a single call then so be it. It just depends on the situation there isn’t really any absolute. The same can be said for printf, sprintf vs. echo and string concatenation. It more or less comes down to personal preference considering the code is going to conduct itself in pretty much the same way. Micromanaging these things are hardly worth the time of day.