ID: 31942
User updated by: adrian-phpbugs at sixfingeredman dot net
Reported By: adrian-phpbugs at sixfingeredman dot net
Status: Open
Bug Type: Variables related
Operating System: Linux
-PHP Version: 4.3.10
+PHP Version: PHP 4.3.11-dev
New Comment:
The version says: (built: Jan 5 2005 08:54:18)
Previous Comments:
------------------------------------------------------------------------
[2005-02-12 00:19:59] adrian-phpbugs at sixfingeredman dot net
Description:
------------
This might be related to #5052. The code below illustrates the problem
pretty well -- the class method should be returning a fresh copy of the
field but in fact the return value is sharing the foreach-counter so
that nested foreaches break. If I do something to force a copy, like
"$foo->_member =& $foo->_member" (I have no idea *why* this forces a
copy), then it works.
Reproduce code:
---------------
<?
class foo {
var $_member = array(1, 2, 3);
function member() {
return $this->_member;
}
}
$foo = new foo();
#$foo->_member =& $foo->_member;
$size = 0;
foreach ($foo->member() as $v) {
$size++;
foreach ($foo->member() as $v) {}
}
if ($size < count($foo->member())) die("BUG FOUND");
Expected result:
----------------
I expect $size == count($foo->member()). If you uncomment the commented
line, it works.
Actual result:
--------------
The inner foreach iterates through every value, but the outer foreach
only iterates through the first value.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31942&edit=1