Bug #72445 [Opn->Nab]: while not considered a part of loop context when breaking from included file.
| From: | nikic@php.net | Date: | Sat, 18 Jun 2016 13:54:17 +0000 |
| Subject: | Bug #72445 [Opn->Nab]: while not considered a part of loop context when breaking from included file. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201715@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72445&edit=1
ID: 72445
Updated by: nikic@php.net
Reported by: maikuolan at gmail dot com
Summary: while not considered a part of loop context when
breaking from included file.
-Status: Open
+Status: Not a bug
Type: Bug
Package: Unknown/Other Function
Operating System: Win7
PHP Version: 7.0.7
Block user comment: N
Private report: N
New Comment:
"include" in PHP is not "#include" in C. It doesn't just copy&paste
your code. The included file has a separate execution context, even though it does inherit some
things, most notably the symbol table from the including scope. You will also notice that writing
"return" in the included file acts as a return from the file, not from the function it
might be included in.
This kind of cross-file goto is definitely not intended to work.
Previous Comments:
------------------------------------------------------------------------
[2016-06-18 13:52:35] maikuolan at gmail dot com
Notes:
- Bug seems to also apply to "foreach" (so, both "foreach" and "while"
are affected by this). However, the bug doesn't seem to apply to "for" (we see the
expected results when substituting for "for").
- "include", "include_once", "require" and "require_once"
all have the same results; Doesn't seem to matter which of these are used.
- Bug only applies when the break exists in an included/required file; If the loop and the break
exist within the same file, the bug won't apply.
------------------------------------------------------------------------
[2016-06-18 13:45:36] maikuolan at gmail dot com
Description:
------------
"while" not considered a part of the loop context when breaking from an included file.
Test script:
---------------
<?php
/** a.php */
$a = false;
while (true) { // Infinite loop
if ($a) {
break;
}
include_once 'b.php';
}
echo 'This message will never be echoed due to this possible bug.';
<?php
/** b.php */
$a = true;
continue;
Expected result:
----------------
Expected: "This message will never be echoed due to this possible bug.".
Actual result:
--------------
Actual: "PHP Fatal error: 'continue' not in the 'loop' or
'switch' context in \b.php on line 5".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72445&edit=1