note 71982 added to control-structures.elseif
| From: | VladimirKornea at osu1 dot php dot net | Date: | Wed, 27 Dec 2006 17:59:47 +0000 |
| Subject: | note 71982 added to control-structures.elseif | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120962@lists.php.net to get a copy of this message | ||
The parser doesn't handle mixing alternative if syntaxes as reasonably as possible.
The following is illegal (as it should be):
<?
if($a):
echo $a;
else {
echo $c;
}
?>
This is also illegal (as it should be):
<?
if($a) {
echo $a;
}
else:
echo $c;
endif;
?>
But since the two alternative if syntaxes are not interchangeable, it's reasonable to expect
that the parser wouldn't try matching else statements using one style to if statement using the
alternative style. In other words, one would expect that this would work:
<?
if($a):
echo $a;
if($b) {
echo $b;
}
else:
echo $c;
endif;
?>
Instead of concluding that the else statement was intended to match the if($b) statement (and
erroring out), the parser could match the else statement to the if($a) statement, which shares its
syntax.
While it's understandable that the PHP developers don't consider this a bug, or don't
consider it a bug worth their time, jsimlo was right to point out that mixing alternative if
syntaxes might lead to unexpected results.
----
Server IP: 64.71.164.2
Probable Submitter: 65.106.184.148
----
Manual Page -- http://www.php.net/manual/en/control-structures.elseif.php
Edit -- https://master.php.net/note/edit/71982
Del: integrated -- https://master.php.net/note/delete/71982/integrated
Del: useless -- https://master.php.net/note/delete/71982/useless
Del: bad code -- https://master.php.net/note/delete/71982/bad+code
Del: spam -- https://master.php.net/note/delete/71982/spam
Del: non-english -- https://master.php.net/note/delete/71982/non-english
Del: in docs -- https://master.php.net/note/delete/71982/in+docs
Del: other reasons-- https://master.php.net/note/delete/71982
Reject -- https://master.php.net/note/reject/71982
Search -- https://master.php.net/manage/user-notes.php