xref: /PHP-7.2/ext/standard/tests/array/bug42850.phpt (revision f1d7e3ca)
1--TEST--
2Bug #42850 (array_walk_recursive() leaves references)
3--FILE--
4<?php
5
6// Bug #42850
7$data = array ('key1' => 'val1', array('key2' => 'val2'));
8function apply_dumb($item, $key) {};
9var_dump($data);
10array_walk_recursive($data, 'apply_dumb');
11$data2 = $data;
12$data2[0] = 'altered';
13var_dump($data);
14var_dump($data2);
15
16// Bug #34982
17function myfunc($data) {
18    array_walk_recursive($data, 'apply_changed');
19}
20function apply_changed(&$input, $key) {
21    $input = 'changed';
22}
23myfunc($data);
24var_dump($data);
25--EXPECT--
26array(2) {
27  ["key1"]=>
28  string(4) "val1"
29  [0]=>
30  array(1) {
31    ["key2"]=>
32    string(4) "val2"
33  }
34}
35array(2) {
36  ["key1"]=>
37  string(4) "val1"
38  [0]=>
39  array(1) {
40    ["key2"]=>
41    string(4) "val2"
42  }
43}
44array(2) {
45  ["key1"]=>
46  string(4) "val1"
47  [0]=>
48  string(7) "altered"
49}
50array(2) {
51  ["key1"]=>
52  string(4) "val1"
53  [0]=>
54  array(1) {
55    ["key2"]=>
56    string(4) "val2"
57  }
58}
59