php魔术方法有哪些
时间:2021-03-19 来源:互联网
今天PHP爱好者给大家带来php魔术方法:1、控制对象序列化时真正处理的部分;2、在反序列化后还原对象属性;3、对象转换成为字符串的机制。赶紧来看看具体的操作教程吧。

本教程操作环境:windows7系统、PHP5.6版,DELL G3电脑。
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;
其他方法同理
以上就是php魔术方法有哪些的详细内容,更多请关注php爱好者其它相关文章!
-
新浪微博网页版快速登录入口-新浪微博官网一键登录 2025-12-21 -
女娲是什么梗?揭秘上古女神爆火全网的搞笑真相,看完秒懂! 2025-12-21 -
币安机构用户区块链地址审计报告审核周期详解 2025-12-21 -
超星学习通网页版登录入口-超星学习通官网入口 2025-12-21 -
在线PS网页版直达入口-Photoshop在线网页版官方网址 2025-12-21 -
乐播传媒网页版登录入口-乐播传媒网页版高清在线观看 2025-12-21