xref: /PHP-8.0/ext/standard/tests/array/bug42850.phpt (revision 7aacc705)
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?>
26--EXPECT--
27array(2) {
28  ["key1"]=>
29  string(4) "val1"
30  [0]=>
31  array(1) {
32    ["key2"]=>
33    string(4) "val2"
34  }
35}
36array(2) {
37  ["key1"]=>
38  string(4) "val1"
39  [0]=>
40  array(1) {
41    ["key2"]=>
42    string(4) "val2"
43  }
44}
45array(2) {
46  ["key1"]=>
47  string(4) "val1"
48  [0]=>
49  string(7) "altered"
50}
51array(2) {
52  ["key1"]=>
53  string(4) "val1"
54  [0]=>
55  array(1) {
56    ["key2"]=>
57    string(4) "val2"
58  }
59}
60