对象串行化和反串行化

[php] view plain copy
 
 print?
  1. <?php  
  2.     include "index.php";  
  3.   
  4.     $p = new person("李四",11,"男");  
  5.   
  6.     //将对象串行化  
  7.     $str = serialize($p);  
  8.       
  9.     //将字符串保存在文件夹obj.txt中  
  10.     file_put_contents("obj.txt",$str);    
  11.   
  12.     //读出字符串从文件中  
  13.     $str = file_get_contents("obj.txt");  
  14.   
  15.     //反串行化  
  16.     $p = unserialize($str);  
  17.   
  18.     echo $p->say();  
  19. ?>  
posted @ 2016-12-22 21:18  天涯海角路  阅读(92)  评论(0)    收藏  举报