php中对象的序列化与反序列化案例附带代码教程
注意:对象的反序列化需要有类的参与,如果没有类在反序列化时候无法确定类
代码如下:
- <?php
- class Student {
- public $name;
- protected $sex;
- private $add;
- public function __construct($name,$sex,$add) {
- $this->name=$name;
- $this->sex=$sex;
- $this->add=$add;
- }
- }
- $stu=new Student('金黑','男','深圳');
- $str = serialize($stu);
- file_put_contents('./ss.txt',$str);
- ?>
复制代码
|
|