![第13节--对象串行化 -- Classes and Objects in PHP5 [13]](http://img.win8xp.cn/noimg.jpg)
|            
第十三节--对象串行化 <?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); ?>  | 
温馨提示:喜欢本站的话,请收藏一下本站!