1.php中的串行化,可以将一个对应放在一个文件中,下次使用的时候,只需要反串行化该文件,即可直接调用。免去了重新new一个对象出来。节省内存,同时该对象也可以在网络中传输,因为一般的对像是放在内存中的,无法通过网络传输。
2.串行化需要借助的参数
/************ 串行化文件 serializa.php ***********/
include "p.class.php"; //p的类文件
$p1=new p();
$str=serialize($p1);
file_put_contents("c:/myserialize.txt",$str);
/******************** 使用串行化的对象,反串行化 ****************************/
#ps:注意需要包含 p 的类文件
include “p.class.php”;
$get_str=file_get_contents("c:/myserialize.txt");
$p=unserialize($get_str);
//现在可以直接调用。。p类中的串行化中的方法了
$p->say();