Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    Using a comma instead of concatenation?

    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 Code:
    <?php
    function myException($exception)
    {
    echo 
    "<b>Exception:</b> " $exception->getMessage();
    }

    set_exception_handler('myException');

    throw new 
    Exception('Uncaught Exception occurred');
    ?>
    Last edited by RonnyNishimoto; 07-20-2012 at 08:19 PM.

  • #2
    New Coder
    Join Date
    Sep 2011
    Location
    Blackpool
    Posts
    53
    Thanks
    7
    Thanked 1 Time in 1 Post
    It joins the two together. So it'd echo "Exception:" + whatever the message is equal to
    Subscribe to a channel dedicated to helping people learn HTML, PHP & CSS.
    http://www.youtube.com/user/RanTutorials

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    56
    Thanks
    4
    Thanked 9 Times in 9 Posts

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by connormcwood View Post
    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 ","?

    Quote Originally Posted by Damo View Post
    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.

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

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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:
    PHP Code:
    $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.

  • Users who have thanked Fou-Lu for this post:

    RonnyNishimoto (07-20-2012)

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,530
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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).

  • Users who have thanked Keleth for this post:

    RonnyNishimoto (07-20-2012)

  • #7
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    But since it can ONLY be used within an echo, it seems out of place to me when its used.
    Quote Originally Posted by Keleth View Post
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •