xref: /PHP-8.4/ext/spl/tests/bug42654_2.phpt (revision 49b2ff5d)
1--TEST--
2Bug #42654 (RecursiveIteratorIterator modifies only part of leaves)
3--FILE--
4<?php
5$data = array ('key1' => 'val1', array('key2' => 'val2'), 'key3' => 'val3');
6
7$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
8foreach($iterator as $foo) {
9    $key = $iterator->key();
10    switch($key) {
11        case 'key1': // first level
12        case 'key2': // recursive level
13            echo "update $key".PHP_EOL;
14            $iterator->offsetSet($key, 'alter');
15    }
16}
17$copy = $iterator->getArrayCopy();
18var_dump($copy);
19?>
20--EXPECT--
21update key1
22update key2
23array(3) {
24  ["key1"]=>
25  string(5) "alter"
26  [0]=>
27  array(1) {
28    ["key2"]=>
29    string(5) "alter"
30  }
31  ["key3"]=>
32  string(4) "val3"
33}
34