|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-09-16 17:56 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2015-09-16 17:56 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 19:00:02 2025 UTC |
Description: ------------ The first cycle has $item defined by reference. The second by value. The $item keeps being a reference to the (last item of the) array even it is used as by value inside the second cycle. As such, the two cycles are not properly isolated as would have been expected. Test script: --------------- <?php $list = array( 'a' => 'x', 'b' => 'y', 'c' => 'z', ); foreach ($list as &$item) { $item .= $item; } foreach ($list as $key => $item) { echo $key . ': ' . $item . "\n"; } ?> Expected result: ---------------- a: xx b: yy c: zz Actual result: -------------- a: xx b: yy c: yy