ID: 47576 User updated by: fischikowski at web dot de -Summary: code-execution dependent on echo Reported By: fischikowski at web dot de Status: Open Bug Type: Scripting Engine problem Operating System: Windows Vista 32bit PHP Version: 5.2.9 New Comment:
I could shorten the test-code (the previous was my original working code): function test() { $array = array("test"); foreach($array as $element) { for($j=0;$j<5;$j++) { continue 2; } return true; } return false; } echo test()?"true":"false"; I expect, that this returns false, because "continue 2" should step to the next foreach-loop (and "return true" should not be executed). But it happens, that true is returned instead. If you insert echo ""; in front of the "return true" everything works fine again (it then returns false). I also noticed, that the outer loop has to be a foreach-loop, if it was a for-loop the result would be also correct. Previous Comments: ------------------------------------------------------------------------ [2009-03-05 17:34:29] fischikowski at web dot de Description: ------------ The echo ""; affects the "return true;" below. As long as the echo is there everything works as expected, if you put "//" in front of the echo, the return will be called even if it should not. Reproduce code: --------------- function matchHostList($host, $list_file) { $host = explode(".", $host); //$list_contents = explode("\n", file_get_contents($list_file)); $list_contents = array("www.google.de"); foreach($list_contents as $list_host) { $list_host = explode(".", rtrim($list_host)); //if the list-host is more specific than the tested host we can't match if(count($host) < count($list_host)) continue; for($i = 1;$i<=count($list_host) && $i <= count($host);$i++) { if($list_host[count($list_host)-$i] != $host[count($host)-$i]) continue 2; } echo ""; //this is necessary to avoid wrong return return true; } return false; } echo matchHostList("false.google.de", "")?"true":"false"; Expected result: ---------------- When running as shown above this returns false (because "continue 2;" continues the loop above the "return true;"), this is OK. If you remove the echo ""; above the "return true;" You would expect that nothing changes (because we only removed some null-output), but in fact the return value changes to true. Actual result: -------------- see Expected result ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47576&edit=1