Professional Web Applications Themes

omitting semicolon - PHP Development

I've been concidering moving from short tags to complete ones. So I'd be converting every single <?= "something" ?> to <?php echo "something" ?>. The thing is: can I safely omit the semicolon in a single command tag. Or should I add it just in case? i.e. <?php echo "something"; ?>. I haven't gotten any warnings about it from php if I leave it out in a code, but is there some strict mode or any other reason why I should include it. The reason I'm asking this is that it seems to work without it, so are there any ...

  1. #1

    Default omitting semicolon

    I've been concidering moving from short tags to complete ones. So I'd be
    converting every single <?= "something" ?> to <?php echo "something" ?>. The
    thing is: can I safely omit the semicolon in a single command tag. Or should
    I add it just in case? i.e. <?php echo "something"; ?>. I haven't gotten any
    warnings about it from php if I leave it out in a code, but is there some
    strict mode or any other reason why I should include it. The reason I'm
    asking this is that it seems to work without it, so are there any
    restrictions to it.


    --
    Welcome to Usenet! Please leave tolerance, understanding
    and intelligence at the door. They aren't welcome here.
    eternal piste erection miuku gmail piste com


    Kimmo Guest

  2. #2

    Default Re: omitting semicolon

    Kimmo Laine wrote:
     

    Yes, in this case you can savely omit the semicolon, as the last line
    before the closing PHP tag closes the script:

    Valid:
    <?php

    print 'hello'

    ?>

    Invalid:
    <?php

    print 'hello'
    print 'dosomething';

    ?>


    JW


    Janwillem Guest

  3. #3

    Default Re: omitting semicolon

    ... and it came to pass that Kimmo Laine
    <com> uttered forth: 

    It helps if you think of the semicolon as a statement *separator*, not
    as a terminator. For instance:

    cmd1;
    cmd2;
    cmd3;

    is the same as:

    cmd1 ; cmd2 ; cmd3;

    In this case, you don't need the trailing semicolon, since it's not
    separating it from anything, ie could be written as:

    cmd1 ; cmd2 ; cmd3

    It is generally regarded as good practise to pop one in, so that
    anything new added to the next line isn't seen as part of the previous
    statement. Compare:

    cmd1 ; cmd2 ; cmd3 ;
    newcmd ;

    If the new line was added yet someone had forgotten to include a
    semicolon after cmd3, PHP would see:

    cmd1 ;
    cmd2 ;
    cmd3 newcmd

    ie: two statements not separated.

    Hope that helps!


    --

    "Dungeon" Dave
    'Dungeon' Guest

Similar Threads

  1. Omitting Trace Statements
    By Jaxim in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: October 1st, 02:49 PM
  2. Omitting form fields if empty
    By JDJones in forum PHP Development
    Replies: 1
    Last Post: September 8th, 06:20 PM
  3. [PHP] omitting the #!
    By Skate in forum PHP Development
    Replies: 0
    Last Post: July 18th, 04:04 PM
  4. omitting the #!
    By Rob Day in forum PHP Development
    Replies: 0
    Last Post: July 18th, 03:49 PM
  5. omitting config values
    By Eric Tishkoff in forum ASP.NET General
    Replies: 2
    Last Post: July 2nd, 05:18 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139