基于序列化与反序列化,在此我只是举一个例子,For example:
class student{
private $name;
private $age;
private $address;
public function __construct($name,$age,$address){
$this->name=$name;
$this->age=$age;
$this->address=$address;
}
public function information(){
echo "My name:".$this->name.";My age:".$this->age."My address:".$this->address;
}
}
$P=new student("小明","25","湖北");
$P->information();
output: My name:小明;My age:25;My address:湖北;
For example:
class student{
private $name;
private $age;
private $address;
public function __construct($name,$age,$address){
$this->name=$name;
$this->age=$age;
$this->address=$address;
}
public function __sleep(){
$arr=array("name","age");
return ($arr);
}
public function __walkup(){
$this->age=30;
}
public function information(){
echo "My name:".$this->name.";My age:".$this->age."My address:".$this->address;
}
}
$P=new student("小红",30,"湖南");
$P->information();
echo "<br>";
$String=serialize($P);
echo $String;
echo "<br>";
$String2=unserialize($String);
$String2->information();
output:
My name:小红;My age:30My address:湖南
O:7:"student":2:{s:13:"studentname";s:6:"小红";s:12:"studentage";i:30;}
My name:小红;My age:30My address: