...

View Full Version : Resolved Using a comma instead of concatenation?



RonnyNishimoto
07-20-2012, 06:56 AM
http://www.w3schools.com/php/php_exception.asp

Why did they use a comma after: echo "<b>Exception:</b>" ,

instead of concatenation? Was that a mistake?



<?php
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}

set_exception_handler('myException');

throw new Exception('Uncaught Exception occurred');
?>

connormcwood
07-20-2012, 08:48 AM
It joins the two together. So it'd echo "Exception:" + whatever the message is equal to

Damo
07-20-2012, 12:14 PM
Here is answer (http://www.lmgtfy.com/?q=php+comma+vs+concat+echo)

RonnyNishimoto
07-20-2012, 08:54 PM
It joins the two together. So it'd echo "Exception:" + whatever the message is equal to

That's the same as concatenation! What's the big difference? Why didn't w3schools teach me about this and instead of using "." all the time, why doesn't everyone just switch to ","?


Here is answer (http://www.lmgtfy.com/?q=php+comma+vs+concat+echo)

Thanks.

The reason I posted it on the forums was because google didn't help me to begin with. What I learned from google was that it's an efficiency difference.

But you see I'm guessing now, and you don't learn by guessing something is right, you learn by knowing something is right. :thumbsup:

And now I still don't know what the answer is. :rolleyes:

Fou-Lu
07-20-2012, 09:02 PM
I'd suggest simply not using commas for consistency sake.
The efficiency aspect is in the range of 1/100000, so you're not really losing anything. But since it can ONLY be used within an echo, it seems out of place to me when its used:


$var = $a . $b;
print $a . $b;
echo $a, $b;

Something just looks wrong with that. It may be that it reminds me of VBA code which I loathe.

Keleth
07-20-2012, 09:14 PM
Yah, it doesn't make all that much sense IMO... I much prefer the period for its consistency outside of echo.

That being said, the comma is concatenation, just limited to echo (I think behaving as a parameter separator as echo is just a function anyway).

Also, never use W3C as a definitive resource... its information is lacking and sometimes wrong. I know people who see me often on this forum might think me always taking a chance to poke at W3C, but I really can't abide a site that has incorrect information and is unwilling to fix it, specially if its the "#1" resource (which it is, but only in search engine rankings).

RonnyNishimoto
07-20-2012, 09:17 PM
But since it can ONLY be used within an echo, it seems out of place to me when its used.


That being said, the comma is concatenation, just limited to echo

There we go! So it has a huge downside that it can only be used with echo and not print and return.

@keleth LOL, w3school misses a lot of parameters and a lot of their code in the tutorials doesn't even work...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum