From: adrian-phpbugs at sixfingeredman dot net Operating system: Linux PHP version: 4.3.10 PHP Bug Type: Variables related Bug description: foreach and object members mixing badly
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 bug report at http://bugs.php.net/?id=31942&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31942&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31942&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31942&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31942&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31942&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31942&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31942&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31942&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31942&r=support Expected behavior: http://bugs.php.net/fix.php?id=31942&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31942&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31942&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31942&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31942&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31942&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31942&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31942&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31942&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31942&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31942&r=mysqlcfg