From: karl at posmaster dot com dot au Operating system: Slackware Linux 2.4.26 PHP version: 5.0.3 PHP Bug Type: Zend Engine 2 problem Bug description: Reference fails after use of unset() on array
Description: ------------ Using "for each" I wanted to remove some items and change others. It seems that the reference in the loop no longer works once unset() has been called on the array. The commented line achieves the desired end, but circumvents the reference. The reference works if the unset() line is commented. This is reproduced without the use of Zend or 3rd part extensions. ----------------------- Reproduce code: --------------- <?php $stuff = array(array('one','two'),array('one','two'), array('three','four'),array('five','six'), array('seven','eight'),array('nine','ten')); var_dump($stuff); foreach ($stuff as $key => &$values) { print "on key:$key<br>"; if(($key%2)==0){ print "Running unset for $key <br>"; unset ($stuff[$key]); }else{ print "Running change for $key <br>"; $values[1]='foo'; // $stuff[$key][1] = 'foo'; } } var_dump($stuff); ?> Expected result: ---------------- I expected to see elements $stuff[1][1], $stuff[3][1] and $stuff[5][1] to be set to 'foo' Actual result: -------------- The elements are left unchanged. Are values 'two', 'six' and 'ten' respectively. -- Edit bug report at http://bugs.php.net/?id=32088&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32088&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32088&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32088&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32088&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32088&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32088&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32088&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32088&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32088&r=support Expected behavior: http://bugs.php.net/fix.php?id=32088&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32088&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32088&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32088&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32088&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32088&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32088&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32088&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32088&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32088&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32088&r=mysqlcfg