These are the magic function in php.
serialize() checks if your class has a function with the magic name __sleep. If so, that function is executed prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn’t return anything then NULL is serialized and E_NOTICE is issued.
Conversely, unserialize() checks for the presence of a function with the magic name __wakeup. If present, this function can reconstruct any resources that the object may have.
- server = $server;
- $this->username = $username;
- $this->password = $password;
- $this->db = $db;
- private function connect()
- $this->link = mysql_connect($this->server, $this->username, $this->password);
- mysql_select_db($this->db, $this->link);
- public function __sleep()
- return array(‘server’, ‘username’, ‘password’, ‘db’);
- public function __wakeup()