From:             jakub dot phpbug at horky dot net
Operating system: Windows Server 2003
PHP version:      5CVS-2004-08-15 (dev)
PHP Bug Type:     Arrays related
Bug description:  By-reference passed value inside foreach() is no longer working

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 bug report at http://bugs.php.net/?id=29687&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29687&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29687&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29687&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29687&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29687&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29687&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29687&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29687&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29687&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29687&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29687&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29687&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29687&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29687&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29687&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29687&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29687&r=float

Reply via email to