php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47576 "continue i;" working wrong on foreach
Submitted: 2009-03-05 17:34 UTC Modified: 2009-05-20 17:22 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: fischikowski at web dot de Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2CVS-2009-04-26 (snap) OS: win32 only - Windows Vista 32bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fischikowski at web dot de
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-10 10:42 UTC] fischikowski at web dot de
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";
?>
 [2009-03-10 13:51 UTC] scottmac@php.net
I can't reproduce this on Linux or OS X

Do you have any Zend Extensions enabled such as eAccelerator, APC, Zend Optimizer or anything like that?
 [2009-03-10 14:43 UTC] fischikowski at web dot de
I don't think to use any. I am using PHP on an apache-webserver, if that makes a difference.

Could also not reproduce this on linux with Version 5.2.6, had no higher versions on a linux system to test it. Will try that later.
 [2009-04-06 12:52 UTC] jani@php.net
Works fine on windows, linux 32/64bit for me.
 [2009-04-07 15:30 UTC] fischikowski at web dot de
Too bad... on my system (and the systems of two friends) we could reproduce this bug.
Maybe we will find out more about the circumstances, when we try to reproduce it during our lecture (starting end of april).
Until then I will not be able to provide any new feedback.
 [2009-04-30 09:16 UTC] jani@php.net
Something is really wrong with the windows builds. This fails with 
latest snapshot (build on 26th of April) I could find.
 [2009-04-30 09:28 UTC] pajoye@php.net
I can reproduce it too.
 
ZE2 Compiler issue? Not much I can do about it right now, assign to Dmitry as he may be better than me to figure out what's wrong here.
 [2009-05-20 17:22 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 06:01:29 2024 UTC