时间:2021-07-01 10:21:17 帮助过:29人阅读
- Listing1 Object serialization
- class User
- {
- public $name;
- public $id;
- function __construct()
- {
- //give user a unique ID 赋予一个不同的ID
- $this->id = uniqid();
- }
- function __sleep()
- {
- //do not serialize this->id 不串行化id
- return(array("name"));
- }
- function __wakeup()
- {
- //give user a unique ID
- $this->id = uniqid();
- }
- }
- //create object 建立一个对象
- $u = new User;
- $u->name = "Leon";
- //serialize it 串行化 注意不串行化id属性,id的值被抛弃
- $s = serialize($u);
- //unserialize it 反串行化 id被重新赋值
- $u2 = unserialize($s);
- //$u and $u2 have different IDs $u和$u2有不同的ID
- print_r($u);
- print_r($u2);
- ?>
http://www.bkjia.com/PHPjc/446474.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446474.htmlTechArticle我们大家有知道PHP串行化可以把变量包括对象,转化成连续bytes数据,你可以将串行化后的变量存在一个文件里或在网络上传输,然后再反...