|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
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: Wed Oct 04 14:01:25 2023 UTC