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 ' = = '; True
if ($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); object is serialized into a string
echo $str. ' <br> ';
$b = Unserialize ($STR); Deserializing objects
Var_dump ($b);
Advanced Features of PHP objects