Home  >  Article  >  Backend Development  >  Serialization of objects into strings and deserialization into objects in php

Serialization of objects into strings and deserialization into objects in php

WBOY
WBOYOriginal
2016-08-08 09:32:561201browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Ngnix timeout problemNext article:Ngnix timeout problem