|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-08-11 12:40 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2021-08-11 12:40 UTC] cmb@php.net
[2021-08-11 12:40 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
[2021-08-11 12:46 UTC] wilhelm at blueend dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 05:00:01 2025 UTC |
Description: ------------ If you have two foreach loops based on the same array and the first loop uses the variable as reference the second loop produces an unexpected result if the variable name for the value stays the same. Test script: --------------- $t = [1,2,3]; foreach ($t as &$testVar){ print_r($testVar); } foreach ($t as $testVar){ print_r($testVar); } Expected result: ---------------- I would expect the same output as if I would have used the non reference variant in the first place. I would expect => (Loop 1) 1,2,3 => (Loop 2) 1,2,>3< Actual result: -------------- I get => (Loop 1) 1,2,3 => (Loop 2) 1,2,>2<