View Single Post
Old 09-17-08, 05:42 PM   #32
nemecb
Registered User
 
Join Date: Jan 2005
Location: Rochester, MN
Posts: 4,018
Default Re: Learn PHP/MySQL Feedback Thread

Quote:
Originally Posted by LovingSticky View Post
You should also not use [dot] to concat strings, much faster is to use comma, as it does not concat them, but just echoes them.

So, this is fastest:

echo '1', $itemid;

This is slower:

echo "1$itemid";

And this would be slowest:

echo "1".$itemid;

All those examples produce same result, of course.
I haven't tried it, but it seems that the , concat is not actually concatenation but a separator for multiple arguments to echo, and thus is not a general purpose replacement for . concatenation. It's a useful suggestion for using echo, but keep in mind that premature optimization is the root of all evil so obfuscating your code to take advantage of this is probably not a good idea (unless of course you discover that you're taking a significant performance hit from that code, but then that wouldn't be premature optimization either). Also, it doesn't apply to the example because the result of the concatenation is being assigned to a variable, not echo'd.

So I guess my point is that it's a useful tip, but your statement that "You should also not use [dot] to concat strings" is not correct without qualification.
nemecb is offline   Reply With Quote