]> granicus.if.org Git - php/commitdiff
Fixed bug #34982 (array_walk_recursive() modifies elements outside function scope)
authorDmitry Stogov <dmitry@php.net>
Fri, 28 Oct 2005 10:06:53 +0000 (10:06 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 28 Oct 2005 10:06:53 +0000 (10:06 +0000)
ext/standard/tests/array/bug34982.phpt [new file with mode: 0755]

diff --git a/ext/standard/tests/array/bug34982.phpt b/ext/standard/tests/array/bug34982.phpt
new file mode 100755 (executable)
index 0000000..9de3408
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #34982 array_walk_recursive() modifies elements outside function scope 
+--FILE--
+<?php
+$ar = array(
+    'element 1',
+    array('subelement1')
+    );
+
+func($ar);
+print_r($ar);
+
+function func($a) {
+  array_walk_recursive($a, 'apply');
+  print_r($a);
+}
+
+function apply(&$input, $key) {
+  $input = 'changed';
+}
+?>
+--EXPECT--
+Array
+(
+    [0] => changed
+    [1] => Array
+        (
+            [0] => changed
+        )
+
+)
+Array
+(
+    [0] => element 1
+    [1] => Array
+        (
+            [0] => subelement1
+        )
+
+)