|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-05-29 07:01 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2015-05-29 07:01 UTC] requinix@php.net
[2015-05-29 14:19 UTC] dp dot maxime at gmail dot com
[2015-05-30 04:25 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Mar 16 15:00:01 2026 UTC |
Description: ------------ foreach construct do not iterate all elements of an array in recursive functions. I am using PHP 5.6.9 from ppa:ondrej/php5-5.6 on Ubuntu 15.04. The version 5.6.4 from the standard Ubuntu 15.04 distribution is also affected. Test script: --------------- <?php function R(&$X, $level) { print "$level X: " . json_encode($X) . "\n"; $A = $X; foreach($A as &$value) { $value = $value - 1; } print "$level A: " . json_encode($A) . "\n"; $B = $X; foreach($B as &$value) { $value = $value + 1; } print "$level B: " . json_encode($B) . "\n"; if ($level < 3) { R($B, $level + 1); } } $X = array(1, 2, 3); R($X, 0); Expected result: ---------------- 0 X: [1,2,3] 0 A: [0,1,2] 0 B: [2,3,4] 1 X: [2,3,4] 1 A: [1,2,3] 1 B: [3,4,5] 2 X: [3,4,5] 2 A: [2,3,4] 2 B: [4,5,6] 3 X: [4,5,6] 3 A: [3,4,5] 3 B: [5,6,7] Actual result: -------------- 0 X: [1,2,3] 0 A: [0,1,2] 0 B: [2,3,4] 1 X: [2,3,4] 1 A: [1,2,3] 1 B: [3,4,4] 2 X: [3,4,4] 2 A: [2,3,3] 2 B: [4,5,4] 3 X: [4,5,4] 3 A: [3,4,3] 3 B: [5,6,4]