The variable is stored in the remove attribute of the class. Although it is saved in the property before calling remove\u all\u filters(), since the value of the property is a reference, the call to remove\u all\u filters() to reset the callback property of the object will still affect the property. The
To further clarify this point, remove\u all\u filters() is not used, but there is a version that performs the operations manually performed by the function. Male removed[$hook] = $all;
$all-> callback =array();
}After seeing this, you may think that the $this->removed[$hook]-> callback cannot be empty, and only the $all-> callback should be empty. But they are not two different. One is a reference to the other. The
The problem with cloning solutions is that you must keep a copy of the object before allowing WordPress remove_all\u filters() to modify it. I am creating a reference instead of saving a copy. The solution to this problem is to use the clone keyword to create a copy of the object when defining the $all property. Here are: Male removed[$hook] = $all;
Remove\u all\u filters ($hook);
}The
}The
}Now $all is a copy of the object that the text printer is working on as remove\u all\u filters (). Complete the task. The
The method object replication of the replication wizard will create a new copy of the object, but all properties as objects are still references. This is one of the reasons why PHP provides the \u clone() magic method. After a new object is copied, this method is called from the copied object. This provides an opportunity to copy attributes that can be referenced if necessary. The following is an example of doing this: Male $value){
If (is_object ($property)){
$this->$property=$this->$property copy;
}The
}The
}The
}Be careful of cloning attacks. I hope this article helps you understand the strict rules of reference and copy differences in PHP. Consider that the next time you don’t have a clear reason to understand how a variable or class property changes suddenly, you may be dealing with the changed reference elsewhere.