Edit report at https://bugs.php.net/bug.php?id=48255&edit=1
ID: 48255 Updated by: poll...@php.net Reported by: faisun at sina dot com Summary: Mixing control structure syntaxes causes parse error Status: Verified Type: Bug Package: Scripting Engine problem Operating System: * PHP Version: 5.*, 6CVS (2009-05-12) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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