News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP: echo- comma or dot?

Started by Tristan Perry, February 09, 2005, 03:47:48 PM

Previous topic - Next topic

Tristan Perry

Hello,
Is there any difference in using either a comma , or a dot . in a PHP statement. What I mean is, is doing what is posted below the same PHP-wise?

<?php
$var 
'Test';

echo 
'This is a '.$test.' code.';
?>

<?php
$var 
'Test';

echo 
'This is a ',$test,' code.';
?>


I use a dot, but I've seen many scripts (Including SMF) use a comma and so am wondering this.
Thanks,
Tau Online

Jack.R.Abbit™

you trying to start some sort of fight?  LOL
I'm sure there will be plenty of people after me that can post some benchmark stats proving that one is better than the other... or vise-versa.  But here's my short answer with no benchmark stats to back it up.  For the most part they are the same.  I believe you will see both in the SMF code.  I'm not too sure why one would be used in place and the other used elsewhere.  I have always used the period... probably always will.  Some times after makeing a mod, I have to force myself to go back and change them all to commas just to fit in.  :)

[Unknown]

There is a difference.  One way outputs each parameter, one by one, without sticking them together and eating a lot more memory.  The other uses more memory, takes more time to convert for echo, and is generally worse.

I've not seen many scripts that use echo with commas.

-[Unknown]

Anguz

Tau, they aren't the same. The dots concatenate the parts and go as one echo, the commas result in a new echo for each part. The dots are a bit slower because it has to concatenate before echoing, multiple echos are faster, specially when you're buffering the output like SMF does.

Jack, I think SMF only uses commas.

BTW, Tau, use spaces: one before and after of dots when concatenating, and only one after when using commas in echos.


echo 'This is a ' . $test . ' code.';
echo 'This is a ', $test, ' code.';


Some reading that may help:
http://phplens.com/lens/php-book/optimizing-debugging-php.php
http://www.simplemachines.org/community/index.php?topic=7110.0

HIH.

Edit: [Unknown] was faster than me typing the reply. ^^
Cristián Lávaque http://cristianlavaque.com

Peter Duggan

Quote from: Tau Online on February 09, 2005, 03:47:48 PM
<?php
$var 
'Test';

echo 
'This is a '.$test.' code.';
?>

<?php
$var 
'Test';

echo 
'This is a ',$test,' code.';
?>


Totally irrelevant to your original question, but haven't you used $test where you meant $var there?

Jack.R.Abbit™

Quote from: Anguz on February 09, 2005, 05:04:23 PM
Jack, I think SMF only uses commas.
Correct.  SMF uses dots in only a few files and for different reasons.  I must have been thinkiing of YSE or early SMF code.

But I'm disappointed that no one posted any benchmark stats showing that one is faster than the other.  :)

[Unknown]

I could but I'm tired of doing it.  I could probably post several links as backup.

-[Unknown]

Tristan Perry

Ah right, thanks for the replies all, they've been helpful  :)

Advertisement: