RecursiveArrayIterator::getChildrens 返回子项的副本,而不是引用
<?php
$stack = array ("some" => "value",
array ("subsome" => "subvalue", array ("subsubsome" => "subsubvalue")),
"some1" => "value1");
$object = new RecursiveArrayIterator ($stack);
$object->next ();
$second_object = &$object->getChildren ();
$second_object->next ();
$third_object = &$second_object->getChildren ();
$third_object->offsetSet ("subsubsome", "subsubdiferent");
var_dump ($object);
var_dump ($second_object);
var_dump ($third_object);
?>
返回
object(RecursiveArrayIterator)#1 (1) {
["storage":"ArrayIterator":private]=>
array(3) {
["some"]=>
string(5) "value"
[0]=>
array(2) {
["subsome"]=>
string(8) "subvalue"
[0]=>
array(1) {
["subsubsome"]=>
string(11) "subsubvalue" <--- 预计会改变
}
}
["some1"]=>
string(6) "value1"
}
}
object(RecursiveArrayIterator)#2 (1) {
["storage":"ArrayIterator":private]=>
array(2) {
["subsome"]=>
string(8) "subvalue"
[0]=>
array(1) {
["subsubsome"]=>
string(11) "subsubvalue" <--- 预计会改变
}
}
}
object(RecursiveArrayIterator)#3 (1) {
["storage":"ArrayIterator":private]=>
array(1) {
["subsubsome"]=>
string(14) "subsubdiferent"
}
}