When using the echo "function" to output a string which is combined of multiple parts, once could write:
echo 'foo' . htmlspecialvars($someVar) . 'bar'
The problem with this is that PHP will first concatenate the three strings (two concatenations) before using echo to dump it to the output. This means that two extra string objects will be created into memory.
The alternative is using comma's. It looks a little weird, but echo then behaves as a function that is taking multiple parameters and dumping all of them:
echo 'foo' , htmlspecialvars($someVar) , 'bar'
In this case, no concatenation is needed which means this code should be faster and more memory-efficient than the concatenating version.
I know the effect of this will be very limited, but I try to use this wherever I can.

Comments
Add Comment