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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 17:01:30 2024 UTC