对象串行化和反串行化
- <?php
- include "index.php";
- $p = new person("李四",11,"男");
- //将对象串行化
- $str = serialize($p);
- //将字符串保存在文件夹obj.txt中
- file_put_contents("obj.txt",$str);
- //读出字符串从文件中
- $str = file_get_contents("obj.txt");
- //反串行化
- $p = unserialize($str);
- echo $p->say();
- ?>

浙公网安备 33010602011771号