php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65232 error if "else" begins with a new php block
Submitted: 2013-07-10 10:31 UTC Modified: 2013-07-10 15:54 UTC
Votes:5
Avg. Score:2.6 ± 1.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: nayana at corp-gems dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
 [2013-07-10 10:31 UTC] nayana at corp-gems dot com
Description:
------------
There is a parse error occurring if the "else" condition is placed in a new block. 
Is this the intended behavior. I was unable to locate documentation that describes 
this behavior. 

<?php if (true) { ?>
            Foo
<?php } ?>
<?php else { ?>
            Bar
<?php } ?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-10 10:35 UTC] me at rudi dot xxx
Source: http://stackoverflow.com/questions/17567868/error-if-else-begins-with-a-
new-php-block

I don't see this as an issue, though. If anything it's a good safeguard against 
even worse PHP code. I would fully expect to read this that the first if block is 
completed, and that the second is treated as new code entirely.

The only special context that should be retained between these open/close braces 
are those that hold an active meaning - for example the contents of an if block 
(anything within }).
 [2013-07-10 15:54 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-07-10 15:54 UTC] ab@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please read about the syntax you trying to use here 
http://php.net/manual/en/control-structures.alternative-syntax.php .
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 18:01:35 2024 UTC