php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13026 if...then...else problem
Submitted: 2001-08-29 08:42 UTC Modified: 2001-08-29 08:44 UTC
From: k_oss30 at hotmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.0.6 OS: Red Hat Linux 7.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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: k_oss30 at hotmail dot com
New email:
PHP Version: OS:

 

 [2001-08-29 08:42 UTC] k_oss30 at hotmail dot com
hi!
i noticed a problem with nested if...then...else s
Example:

if ($A==1):
  if ($B==2) DoThis();
  if ($C==3) DoThat();
else:
  DoSomething;
endif;

in this case - the 'else:' on thr 4th line is regarded as an 'else' continuing from the 'if' on the 3rd line.
this generates a parser error.
this may cause confusion to some of you (it did to me) but the workaround is this:

if ($A==1) {
  if ($B==2) DoThis();
  if ($C==3) DoThat();
} else {
  DoSomething;
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-29 08:44 UTC] derick@php.net
It's not really a bug, but a side-effect of the old syntax. The new one, with { } does not have this problem, and that's the recommended syntax anyways.
I'll mark this one as bogus.

Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 17:01:30 2025 UTC