php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50173 Alternative Syntax Else Issue
Submitted: 2009-11-14 02:38 UTC Modified: 2009-11-23 21:11 UTC
From: kevinarcher15 at hotmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0 OS: CentOS 5
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kevinarcher15 at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-11-14 02:38 UTC] kevinarcher15 at hotmail dot com
Description:
------------
PHP is confusing else as part of the nested if statement above it. When removing the colon and replacing it with a left brace { it says unexepected '{' expecting ':'... Placing any line of code below the nested if will stop the problem from occurring, even while(false) { } prevents it. So it makes sense why its happening, however based on the syntax and alternative syntax it looks acceptable and PHP even seems to have an idea that the else is part of the alternative syntax. Test on stable 5.3.0 and 5.3.1-dev (August 15 2009).

Reproduce code:
---------------
if(true):
    if(true) {
        echo 'exepected';
    }
else:
    echo 'not here';
endif;

Expected result:
----------------
expected

Actual result:
--------------
PHP Parse error:  syntax error, unexpected ':' in /home/archer/test.php on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-14 21:23 UTC] jani@php.net
Do not mix the syntax. You're not only confusing the engine, you're confusing yourself as well. Needs a note in the manual page here:

http://www.php.net/manual/en/control-structures.alternative-syntax.php
 [2009-11-23 21:11 UTC] svn@php.net
Automatic comment from SVN on behalf of bjori
Revision: http://svn.php.net/viewvc/?view=revision&revision=291231
Log: Fixed bug#50173 (Alternative Syntax Else Issue)
 [2009-11-23 21:11 UTC] bjori@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 18:01:28 2024 UTC