我以前从未遇到过这样的问题-实际上是用任何一种语言。
我最初有一个来自JSON的对象。我不想更改此对象,而只是将其用作出于各种目的的副本。
在此示例中,我不想更改的对象具有lorem ipsum,因为我认为实际的内容无关紧要。
//Inside the Object I don't want to alter, consider it a template/structure: {"random_key"=>"","another_random_key_with_an_int"=>1}
function random_func(){
$local_scope_object = $this->original_instance;
$local_scope_object->random_key = "now has data";
return $local_scope_object;
}
如您在上面看到的,有一个对象返回到处理程序,但现在暂时忽略它。
当我var_dump($this->original_instance);
时,我希望实例保持不变,并且其键random_key
保持为空;但它会受到影响。
这可能是什么,因为我没有声明本地范围var像(使用amp&)$local_scope_object = &$this->original_instance
一样?