#29687 [Opn->Ver]: By-reference passed value inside foreach() is no longer working

From: Date: Mon, 07 Mar 2005 19:16:25 +0000
Subject: #29687 [Opn->Ver]: By-reference passed value inside foreach() is no longer working
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75040@lists.php.net to get a copy of this message
ID: 29687 Updated by: sniper@php.net Reported By: jakub dot phpbug at horky dot net -Status: Open +Status: Verified -Bug Type: Arrays related +Bug Type: Zend Engine 2 problem -Operating System: Windows Server 2003 +Operating System: * -PHP Version: 5CVS-2004-08-15 +PHP Version: 5CVS-2005-03-07 Previous Comments: ------------------------------------------------------------------------ [2004-08-15 15:19:47] jakub dot phpbug at horky dot net Description: ------------ A value passed inside foreach() costruct by reference does not reflect the changes made to that value when the iterated array is touched by some array function, like key() or current(). In example below, if you comment out the key() line, it will work OK. I think that this bug is closely related to the bug #28939. Reproduce code: --------------- <?php $array = array("NO", "NO", "NO"); foreach($array as $index => &$item) { key($array); // there may be also current(), reset(), // first(), next(), prev(), foreach etc. $item = "YES"; var_dump($item); } print_r($array); ?> Expected result: ---------------- string(3) "YES" string(3) "YES" string(3) "YES" Array ( [0] => YES [1] => YES [2] => YES ) Actual result: -------------- string(3) "YES" string(3) "YES" string(3) "YES" Array ( [0] => YES [1] => NO [2] => NO ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29687&edit=1

« previous php.bugs (#75040) next »