Home >Backend Development >PHP Tutorial >Serialization of objects into strings and deserialization into objects in php
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;
if ($a == $b) echo '=='; //true
if ($a === $b) echo '==='; //false Quote
$str = serialize($a); //Object serialized into string
echo $str.'
';
$c = unserialize($str); //Deserialize to object
var_dump($c);
The above introduces the serialization of objects into strings and deserialization into objects in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.