SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    K. Yank Giving Bad Coding Tips?

    Well, maybe that's an exaggeration, but in his book he always runs echo like this:

    echo ("echoed text" );

    Why does he enclose it in parentheses? echo isn't even a function, it's a language construct, so it doesn't need them. It complicates things for php n00blars. :O

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesnt matter, its just a personal preference.

  3. #3
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I think for 'noobs' it makes a little more sense because it ties in with how every other function works - ok it's not a function . Although I no longer use the print("blah, blah..."); statement, it made perfect sense to me at the start of my programming, and helped me avoid sloppy mistakes.

    Once I learnt to avoid using double quotes for things that do not need parsing, I soon started using the shorter methods, but it really does seem a preference thing. Maybe somebody far wiser than me can enlighten us with a true or perhaps more valid reason.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Phil.Roberts
    It doesnt matter, its just a personal preference.
    Not always:

    ... if you want to pass more than one parameter to echo, you must not enclose the parameters within parentheses
    http://www.php.net/manual/en/function.echo.php

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still use them - couldn't now use ECHO after all this time w/out those brackets.

    Believe me - they're a life safer during debugging and script reinvention -

    I've been there and done that - even bought the mug You have absolutely nothing to loose by using them, so keep using them....

  6. #6
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But it's also teaching anyone who reads it to basically go against the more popular trend of not enclosing them in braces.

  7. #7
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I usually use parenthesis when my echo statement will span more than one line in my code.

    I think it marks the beginning and end of the statement off a little better for me .

    Example:

    PHP Code:
    echo('I\'m gonna echo some stuff so you '.
         
    'can see what I\'m talking about.  <br>'.
         
    'This sentence is on its own line. <br>' 
        
    ); 


    --ed

  8. #8
    SitePoint Zealot Egghead's Avatar
    Join Date
    Feb 2002
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CeleronXL
    But it's also teaching anyone who reads it to basically go against the more popular trend of not enclosing them in braces.
    Goodness gracious, fashions in the programming world! Whatever next?

  9. #9
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In such a thing as coding, being different is not a good thing.

  10. #10
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason commas don't work within the parentheses is because that is considered one thing to echo, you could go like this:

    PHP Code:
    echo ('some text'), ('some other text'); 
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  11. #11
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But why 'hack' (ok, extreme!) your way round it when you could just leave the parenthesis out

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  12. #12
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not hacking, the parenthesis are meant to group them together, which is why it even accepts them using echo, so doing it the way I previously mentioned is in fact correct.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  13. #13
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I don't use parenthesis and never have. I also never have an echo statement that spans multiple lines, I would exit out of PHP for something like that.
    PHP Code:
    <?php
    /* blah blah */
    ?>
    <span class='something'><? echo $name?> is <? echo $age?> years old.</span>
    <?php
    /* blah blah */
    ?>

  14. #14
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, if we're nitpicking, why are you using /* */ on the same line, DJ. It's unnecessary and abnormal. What? It's your preference? That's not allowed! What? It still works? So what, it's not proper!

    Please!

    Worry about something else, guys.
    Aaron Brazell
    Technosailor



  15. #15
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Sketch
    Worry about something else, guys.
    A sane mind!

  16. #16
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great Minds think differently.

  17. #17
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do it the same as DJ's method Hardly ever have the need to print single lines unless it's debugging something

    Who cares, I like the print ("hello"); it just "fits". And the same in langauges like Java system.out.println("hello!");

  18. #18
    SitePoint Enthusiast imati0n's Avatar
    Join Date
    Feb 2003
    Location
    Savannah, GA
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I personally prefer it because it's easier to find your mistakes for newbs.. like me

  19. #19
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't really care.

  20. #20
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    How does it help you find your mistakes? I've never seen this method of echoing before.
    Chrispian H. Burks
    Nothing To Say

  21. #21
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Believe me - they're a life safer during debugging and script reinvention -
    Just how do these "()" in the echo statement help you debug?
    John

  22. #22
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's what I'm trying to figure out. It seems like you are prone for more errors, by not closing it:

    echo ("test";

    I too leave PHP for HTML, and use short tags (<?=$var?>) to display the variables.

  23. #23
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't even escape out of PHP. I just load up a variable with all the generated HTML and then echo it out when I'm done.
    PHP Code:
    $pageBody "<form...>...";
    echo 
    $pageBody
    John


Bookmarks

Posting Permissions

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