| Bug #838 | Parser error in nested if | ||||
|---|---|---|---|---|---|
| Submitted: | 9 Oct 1998 5:47am UTC | Modified: | 9 Oct 1998 8:20am UTC | ||
| From: | agarcia at at4 dot net | Assigned to: | |||
| Status: | Closed | Category: | Parser error | ||
| Version: | 3.0.5 | OS: | win95 and linux 2.035 RH5.0 | ||
[9 Oct 1998 8:20am UTC] zeev
How is it clear? Because you've indented it that way? :) It's not clear at all, and in fact, the solution for the dangling else shift/reduce problem clearly states that the else belongs to the closest IF. PHP makes no distinction between if's with braces, no braces, or colons, and it doesn't pay attention to your indentation either. As soon as it sees the elseif, it expects it to match the inner IF sentence, and since it doesn't, it fails.

This script causes a parser error: <? $a = $b = 2; if ($a==2): if ($b==2) print "a=2 b=2<br>"; elseif ($a=3): print "a=3<br>" endif; ?> This script also fails: <? $a = $b = 2; if ($a==2): if ($b==2) {print "a=2 b=2<br>"}; elseif ($a=3): print "a=3<br>" endif; ?> Based in the fact that this code isn't correct: if ($b==2) print "a=2 b=2<br>"; elseif ($a=3): print "a=3<br>"; endif; i think it's clear the elseif ($a=3): belongs to the previous if sentence.