php魔术方法:
_sleep() 可以控制对象序列化时真正处理的部分
_wakeup() 在反序列化后还原对象属性
_toString() 对象转换成为字符串的机制
把php变量转换成一串编码后字符串,方法为serialize() 反序列化unserialize()
//序列化 class testSerialize{ public $a = 10; public $b = 15; public $c = 20; function _construct(){ $this->b = $this->a * 10; $this->c = $this->b * 2; } } $k = serialize(new testSerialize()); echo $k;// out: O:13:"testSerialize":3:{s:1:"a";i:10;s:1:"b";i:15;s:1:"c";i:20;} $j = unserialize($k);
sleep方法:
class testSerialize1{ public $a = 10; public $b = 15; public $c = 20; function _construct(){ $this->b = $this->a * 10; $this->c = $this->b * 2; } function __sleep(){ return $this->a; } } $k = serialize(new testSerialize1()); echo $k;
其他方法同理
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)