Bug #48255 [Ver->Nab]: Mixing control structure syntaxes causes parse error
| From: | danack@php.net | Date: | Fri, 15 Jan 2016 13:43:16 +0000 |
| Subject: | Bug #48255 [Ver->Nab]: Mixing control structure syntaxes causes parse error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198680@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48255&edit=1
ID: 48255
Updated by: danack@php.net
Reported by: faisun at sina dot com
Summary: Mixing control structure syntaxes causes parse error
-Status: Verified
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: *
PHP Version: 5.*, 6CVS (2009-05-12)
Block user comment: N
Private report: N
New Comment:
Changing to not a bug as mixing syntaxes in the same control block is not supported.
Previous Comments:
------------------------------------------------------------------------
[2014-02-06 21:27:07] volker at volkers-harfen dot de
Seems to be no bug for me, because documentation writes (at http://www.php.net/manual/en/control-structures.alternative-syntax.php):
Note:
Mixing syntaxes in the same control block is not supported.
This code causes no syntax too, because the if { ... } is in {...} control block:
<?php
if(2>1):
echo "ABCD";
{if(4>3){ echo "EFGH"; }}
else:
echo "123456";
endif;
?>
------------------------------------------------------------------------
[2012-07-03 15:02:48] pollita@php.net
So, what's happening is that the parser is associating the else: with the normal
style if block on the line immediately above it, and of course mixing in a
single if/else like that is verboten.
Should it be fixed? Probably, but it's a serious edge case, and massaging the
parser to cope with it is much harder than the following workaround:
<?
if(2>1):
echo "ABCD";
if(4>3){ echo "EFGH"; };
else:
echo "123456";
endif;
?>
Note the extra semicolon added after the inner-if statement. This is enough to
terminate that expression and ensure that the else statement binds to the right
if.
Leaving this bug report open, because it is definitely a bug, but I'm not sure
who's going to invest the cycles on it.
------------------------------------------------------------------------
[2010-05-05 21:16:33] whatrevolution at yahoo dot com
Bug OP test, result:
( ! ) Parse error: syntax error, unexpected ':' in
/var/www/php_bugs/mixed_control_structure.php on line 5
PHP Version 5.2.10-2ubuntu6.4
System Linux 2.6.31-20-generic x86_64
Build Date Jan 6 2010 22:36:47
Server API Apache 2.0 Handler
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Apache/2.2.12 (Ubuntu)
------------------------------------------------------------------------
[2009-05-13 04:05:30] faisun at sina dot com
Description:
------------
PHP Version: 5.2.9.2
<?
if(2>1):
echo "ABCD";
if(4>3){ echo "EFGH"; }
else:
echo "123456";
endif;
?>
Result: Parse error: parse error in E:\wwwroot\1.php on line 5
<?
if(2>1):
echo "ABCD";
if(4>3){ echo "EFGH"; } else{}
else:
echo "123456";
endif;
?>
Result:ABCDEFGH
Reproduce code:
---------------
<?
if(2>1):
echo "ABCD";
if(4>3){ echo "EFGH"; }
else:
echo "123456";
endif;
?>
Expected result:
----------------
ABCDEFGH
Actual result:
--------------
Parse error: parse error in E:\wwwroot\1.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48255&edit=1