Thiago Melo de Paula wrote:
Hello Yeti!
This is a very good question, because it shows that you're interested in get
the max from your PHP codes.
In my research about php optimization, I couldn't find any relevant article
about this specific issue, but some sites tell us that using commas instead
periods on echo constructor would be faster.
I agree with that, because using the concatenation symbol, will cause PHP to
take steps to process the concatenation.
But I think (I never did any performances tests on this subject) that the
gain would be irrelevant on a general site.
Regards from Brazil.
Thiago Melo de Paula
On Mon, Aug 25, 2008 at 10:25 AM, Yeti <yeti@xxxxxxxxxx> wrote:
So it is faster to output various strings using the "," instead of "."?
Sara Golemon (one of the PHP devs) once wrote an article which covers
(amongst others) this:
http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html
The bottom point: using a comma is slightly faster and uses slightly
less memory (which may or not be significant, depending on the situation).
Do note though, that the ORDER of execution is different when comparing
echo a().b().c(); vs. echo a(),b(),c() !! (with concatenation it will
first execute ALL functions, and THEN concatenate them together. With
commas it will start left, execute, output, and then continue to the
right.). If you directly send something to the output from within those
functions, you'll notice it. If you only return a string from it, you
won't. :)
so:
<?php
function a() {
echo 'a';
return 'a';
}
function b() {
echo 'b';
return 'b';
}
echo a().b(); // will return: "abab" (function a called, outputs a.
Return value stored. function b called, outputs b. Return value stored.
The two return values are concatenated, and sent to output)
echo "\n";
echo a(),b(); // will return "aabb" (function a called, outputs a.
Return value is also immediately sent to output. function b called,
outputs b. Return value is also immediately sent to output)
I hope that clears it up a bit.
- Tul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php