日期:2011-05-19 浏览次数:20506 次
<?PHP class User { public $name; public $id; function __construct() { //give user a unique ID 赋予一个不同的ID $this->id = uniqid(); } function __sleep() { //do not serialize this->id 不串行化id return(array("name")); } function __wakeup() { //give user a unique ID $this->id = uniqid(); } } //create object 建立一个对象 $u = new User; $u->name = "Leon"; //serialize it 串行化 注意不串行化id属性,id的值被抛弃 $s = serialize($u); //unserialize it 反串行化 id被重新赋值 $u2 = unserialize($s); //$u and $u2 have different IDs $u和$u2有不同的ID print_r($u); print_r($u2); ?>