Page 1 of 1
Missing semicolon doesn't error
Posted: Wed Sep 06, 2006 10:47 am
by RobertGonzalez
Ok, I thought I knew it all (ok most, at least) but while testing today I did this:
and I got no errors. When I did this:
Code: Select all
<?php
phpinfo()
if ($yardley) {
echo 'Whos da man';
}
?>
and this
Code: Select all
<?php
phpinfo();
if ($yardley) {
echo 'Whos da man'
}
?>
I did get errors. How come that happens? I have never tried that before, but it seems odd that a missing semicolon would not throw an error. Or am I missing something.
Posted: Wed Sep 06, 2006 10:53 am
by Luke
Haven't you ever done this?
Code: Select all
<a href="<?php echo $page ?>">Some Place</a>
When there is just one statement on the page... semicolon can be omitted.
Posted: Wed Sep 06, 2006 11:52 am
by Mordred
Read the *cough*
*cough* 
Posted: Wed Sep 06, 2006 2:30 pm
by Oren
Everah, I bet you didn't learn PHP from a book. Am I right?
Posted: Wed Sep 06, 2006 2:33 pm
by s.dot
The closing tag of a block of PHP code automatically implies a semicolon
I wasn't aware of that either. Nifty!
Posted: Thu Sep 07, 2006 11:32 pm
by RobertGonzalez
Oren wrote:Everah, I bet you didn't learn PHP from a book. Am I right?
You got it. I learned it from tutorials, this forum and good old trial and error...
The Ninja Space Goat wrote:Haven't you ever done this?
Code: Select all
<a href="<?php echo $page ?>">Some Place</a>
When there is just one statement on the page... semicolon can be omitted.
... but I have never made this 'error'. The way I learned PHP was to always terminate your lines. Good thing is you are never too advanced to learn the language (unless you are feyd

).
Posted: Fri Sep 08, 2006 6:03 am
by Oren
I always add the semicolon even when it's not needed - so if I add new lines I don't need to add it.
Posted: Fri Sep 08, 2006 10:42 am
by RobertGonzalez
I have always been of the mind set that if you open something in the code, you close, even if it is not necessary (like ending PHP tags, <db>_close(), etc). It just seems right.