__sleep,PHP, Question, php5 magic methods,__sleep and __wakeup,What’s the special meaniacng of __sleep and __wakeup,__sleep and __wakeup in PHP
What’s the special meaning of __sleep and __wakeup?


__sleep returns the array of all the variables than need to be saved.
 __wakeup retrieves them.


__sleep() and __wakeup() run prior to serialize() and unserialize() respectively.


Example:
<?php
class DBConn
{
    protected $conn;
    private $host, $username, $password, $db;
    
    public function __construct($host, $username, $password, $db)
    {
        $this->host = $host;
        $this->username = $username;
        $this->password = $password;
        $this->db = $db;
        $this->connect();
    }
    
    private function connect()
    {
        $this->conn = mysql_connect($this->host, $this->username, $this->password);
        mysql_select_db($this->db, $this->conn);
    }
    
    public function __sleep()
    {
        return array('host', 'username', 'password', 'db');
    }
    
    public function __wakeup()
    {
        $this->connect();
    }
}
?>