Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Tristan Perry on February 09, 2005, 03:47:48 PM

Title: PHP: echo- comma or dot?
Post by: Tristan Perry on February 09, 2005, 03:47:48 PM
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
Title: Re: PHP: echo- comma or dot?
Post by: Jack.R.Abbitâ„¢ on February 09, 2005, 04:29:40 PM
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.  :)
Title: Re: PHP: echo- comma or dot?
Post by: [Unknown] on February 09, 2005, 04:57:12 PM
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]
Title: Re: PHP: echo- comma or dot?
Post by: Anguz on February 09, 2005, 05:04:23 PM
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. ^^
Title: Re: PHP: echo- comma or dot?
Post by: Peter Duggan on February 09, 2005, 06:47:32 PM
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?
Title: Re: PHP: echo- comma or dot?
Post by: Jack.R.Abbitâ„¢ on February 10, 2005, 01:50:29 AM
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.  :)
Title: Re: PHP: echo- comma or dot?
Post by: [Unknown] on February 10, 2005, 01:55:01 AM
I could but I'm tired of doing it.  I could probably post several links as backup.

-[Unknown]
Title: Re: PHP: echo- comma or dot?
Post by: Tristan Perry on February 10, 2005, 12:23:43 PM
Ah right, thanks for the replies all, they've been helpful  :)