1--TEST-- 2Test str_replace() function and array refs, more cases 3--FILE-- 4<?php 5$closure = function (array $array, array $keys, $value) 6{ 7 $current = &$array; 8 foreach ($keys as $key) 9 $current = &$current[$key]; 10 $current = $value; 11 return $array; 12}; 13 14class SomeClass { public $prop; } 15 16$obj = new SomeClass; 17$obj->prop = ['x' => 'property']; 18$obj->prop = $closure($obj->prop, ['x'], 'a'); 19var_dump(str_replace(array_keys($obj->prop), $obj->prop, "x property")); 20 21$array = ['x' => 'property']; 22$array = $closure($array, ['x'], 'a'); 23var_dump(str_replace(array_keys($array), $array, "x property")); 24--EXPECT-- 25string(10) "a property" 26string(10) "a property" 27