Search code examples
phpperformancestringoutput-buffering

echoing multiple arguments when output_buffering is on


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 ?


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.