Object comparison, when all the properties of two instances of the same class are equal, you can use the comparison operator = = To determine whether a two variable is a reference to the same object, you can use the congruent operator = = =.
Class Car {} $a = new car (), $b = new Car (), if ($a = = $b) echo ' = = '; Trueif ($a = = = $b) echo ' = = = '; False
Object replication, in some special cases, you can copy an object by using the keyword clone, at which point the __clone method is called, and the value of the property is set by this magic method.
Class Car {public $name = ' car '; Public Function __clone () { $obj = new Car (); $obj->name = $this->name; }} $a = new car (), $a->name = ' new car '; $b = clone $a; var_dump ($b);
Object serialization, which can be serialized as a string by the Serialize method, used to store or pass data, and then deserialize the string into an object when needed by Unserialize.
Class Car {public $name = ' car ';} $a = new Car (); $str = serialize ($a); The object is serialized into a string echo $str. ' <br> '; $b = Unserialize ($STR); Deserializes to Object Var_dump ($b);
Advanced Features for PHP classes and object objects