|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #838 Parser error in nested if
Submitted: 1998-10-09 05:47 UTC Modified: 1998-10-09 08:20 UTC
From: agarcia at at4 dot net Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.5 OS: win95 and linux 2.035 RH5.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: agarcia at at4 dot net
New email:
PHP Version: OS:


 [1998-10-09 05:47 UTC] agarcia at at4 dot net
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>"
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>"

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>";

i think it's clear the elseif ($a=3):
belongs to the previous if sentence.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [1998-10-09 08:20 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  
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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Nov 28 20:01:27 2023 UTC