Question

One of Googles Let's make the internet faster talks included something about using echo with multiple arguments in PHP instead of using print or string concatenation.

echo 'The ball is ', $color;

Rather than either of these

echo "The ball is $color";
echo 'The ball is ' . $color;

What if output buffering is in play ?

What would be the difference between using echo with multiple arguments along with output buffering, vs using the alternate methods without output buffering ?

Was it helpful?

Solution

Be sure to read the PHP team's rebuttal of Google's performance tips.

Specifically, he (Gwynne Raskind) says:

4) "Don't use concatenation with echo."

This is exactly the opposite of correct advice. The engine handles multiple arguments to echo() in such a way that concatenation (or double-quoted string interpolation) is actually much faster. See the benchmark posted at http://pastie.org/523020.

OTHER TIPS

the first version should be a bit faster because it doesn't have to parse the string for variable expansion (single quotes) and it doesn't have to spend time concatenating the two strings before writing them. i don't think that buffering will affect this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top