|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-08 17:55 UTC] derick@php.net
[2007-01-08 18:06 UTC] ugo at iliona dot net
[2007-01-08 18:10 UTC] derick@php.net
[2007-01-08 18:26 UTC] ugo at iliona dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 23:00:01 2025 UTC |
Description: ------------ Hello, This bug was tried on multiple Unix versions and multiple processors (32/64bits), and multiple PHP5 versions (including 5.2.0), so it seems really to be on the side of PHP. After using a foreach with a referenced value, and then another foreach (without the referenced value), the original array is broken. Apparently, the last value of the array takes the value of the n - 1 last value. I've reduced the problem to its simplest form and attached it to this bug report. Greeting, Ugo PARSI Reproduce code: --------------- <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } print_r($arr); foreach ($arr as $value) { $value = $value; } print_r($arr); ?> Expected result: ---------------- Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Actual result: -------------- Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 ) Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 6 )