PHP provides two functions, one is serialize and the other is unserialize. So what are the uses of these two functions?
Serialization can serialize any data type in php except resource into a string. Here, we take an object as an example and define a class at will
class vb{
private $a;
private $ b;
function __construct($a='peng',$b='luo'){
$this->a=$a;
$this->b=$b;
}
We will $obj serialization $c= serialize($obj); After printing out $c, we get O:2:"vb":2{s:5:"vba";s:4:"peng";s: 5:"vbb";s:3:"luo";} We will deserialize this string again, $c=unserialize($c); and print it out print_r($c);
vb Object ( [a:private] => peng [b:private] => luo )
At this point we get an object, we can call the properties and methods in the object
echo $c-> ;speak();