Copy Code code as follows:
<?php
Class simpleclass{
Public $var = ' a default value ';
Public Function Displayvar () {
Echo $this->var;
}
}
$instance = new Simpleclass ();
$assigned = $instance;
$reference =& $instance;
$instance->var = ' $assigned'll have this value ';
$instance = null; $instance and $reference become null var_dump ($instance); Var_dump ($reference); Var_dump ($assigned);
Var_dump ($instance);
Var_dump ($assigned);
Var_dump ($reference);
?>
PHP5 rewrites the OOP bottom. When a class generates an instance (object), the return value $instance is not the object itself, but only an ID (or resource handle) of the object, so when $instance is assigned to $assigned, $assigned also points to the object. This is somewhat like a reference (&) operation of a generic variable. So, when the $instance is initialized, the $assigned is initialized. However, when $instance is destroyed (=null), the object is not destroyed and the destructor is not triggered because the corresponding object also has a handle present ($assigned). As a result, Var_dump ($assigned) is the value of the object, and $instance is already an empty handle, showing null. $reference because it has a reference relationship with a common variable like $instance, it also becomes an empty handle and displays null.