Strange IF(condition) behaviour
| From: | Tim L | Date: | Tue, 06 Jan 2004 03:57:55 +0000 |
| Subject: | Strange IF(condition) behaviour | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-173815@lists.php.net to get a copy of this message | ||
I'm not sure if this is intended behaviour or not, but I can see that is
might be. Just thought I would bounce this to see what people think about
it:
<?php
if (false)
?>Hello<?php
else
echo "Hi";
echo " World\n";
?>
This returns a parse error due to the fact there is no brackets around the
first part of the if statement. It seems that because the next line after
the if is not php, then it terminates the if at the closing of the php tag.
But if you do this:
<?php
if (false)
?>Hello<?php
?>
or
<?php
if (true)
?>Hello<?php
?>
The word "Hello" is always output for the same reason.
I can understand why to some extent in the way that is behaves, but it
depends on your point of view as to what "statement" (as per the manual)
actually means. Why can the bracketed version of if conditionaly display
html, yet the unbracketed lazy man version cant?
Any ideas as to whether or not this is supposed to happen like this or not?
Tim