|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-12 00:19 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 15:00:02 2025 UTC |
My project was missing the following code after calling a recursive function. As a result, my project does not re-produce the bug described in this report: /* Let's sort through the subcategory's arrays. */ $retval = $this->getProperItem($priv_item, $relationNum); if ( $retval != NULL ) { return $retval; }