当前位置: 首页 > 后端技术 > PHP

对象序列化(serialization)

时间:2023-03-29 18:25:01 PHP

1.对象序列化1.将对象转为字符串(不用懂)classPerson{var$name;public$arr=array("aaa","bbb","ccc");函数__construct($name){$this->name=$name;}functionsay(){echo$this->name."
";}函数__clone(){$this->name="ni";}函数__call($method,$args){if(in_array($method,$this->arr)){echo$args[0]."
";}else{echo"你调用的方法{$method}()不存在!
";}}};$p=newPerson("wo");$s=序列化($p);file_put_contents("result.txt",$s);echo"保存成功!";2.反向反序列化3.对象在网络中传输时需要序列化??4.对象持久化时需要序列化