mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
We need to carry around a reference to the underlying Bucket to be able to modify it by reference. Closes GH-10749 Signed-off-by: George Peter Banyard <girgias@php.net>
34 lines
728 B
PHP
34 lines
728 B
PHP
--TEST--
|
|
Bug #42654 (RecursiveIteratorIterator modifies only part of leaves)
|
|
--FILE--
|
|
<?php
|
|
$data = array ('key1' => 'val1', array('key2' => 'val2'), 'key3' => 'val3');
|
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));
|
|
foreach($iterator as $foo) {
|
|
$key = $iterator->key();
|
|
switch($key) {
|
|
case 'key1': // first level
|
|
case 'key2': // recursive level
|
|
echo "update $key".PHP_EOL;
|
|
$iterator->offsetSet($key, 'alter');
|
|
}
|
|
}
|
|
$copy = $iterator->getArrayCopy();
|
|
var_dump($copy);
|
|
?>
|
|
--EXPECT--
|
|
update key1
|
|
update key2
|
|
array(3) {
|
|
["key1"]=>
|
|
string(5) "alter"
|
|
[0]=>
|
|
array(1) {
|
|
["key2"]=>
|
|
string(5) "alter"
|
|
}
|
|
["key3"]=>
|
|
string(4) "val3"
|
|
}
|