Curious

Started by draker, August 05, 2004, 11:10:24 PM

Previous topic - Next topic

draker

Okay, I've been coding in PHP for a while now - self taught but able to proudce a fairly decent RPG CMS amazingly enough - and I noticed with SMF that the developers instead of using the normal concatenation command of ' . ' you used ','.  I'm just curious, but what's the difference/benefits of one over the other? 

Shoeb Omar

I don't know the details, but as I understand it, using ',' is faster...

[Unknown]

Ahem. (sorry, I've explained this many a time to many different PHP programmers, and it's kinda long.. gotta clear my throat.)

See, the normal method might be like this:

echo 'a' . 'b' . 'c';

This is, yes, string concatenation.... equivalent to:

$temporary = 'a' . 'b' . 'c';
echo $temporary;

The method employed a lot in SMF is this:

echo 'a', 'b', 'c';

Which is NOT equivalent to:

$temporary = 'a', 'b', 'c';
echo $temporary;

Instead, it's passing three parameters to the echo contruct.  Then, echo handles each and outputs each.  Because SMF always uses an output buffer, this is faster... but it is not concatenation.. rather, just sending the variables separately and more efficiently.

-[Unknown]

Advertisement: