|
Posted by Dungeon' Dave on 08/24/05 00:36
... and it came to pass that Kimmo Laine
<eternal.erectionN05P@Mgmail.com> uttered forth:
>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.
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
Navigation:
[Reply to this message]
|