|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-03-05 17:34 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
Except from the "<?php" and "?>" I already posted the shorter script. <?php function test() { $array = array("test"); foreach($array as $element) { for($j=0;$j<5;$j++) { continue 2; } //inserting code here affects return-value return true; } return false; } echo test()?"true":"false"; ?>