These are  the magic function in php.
__sleep
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.
__wakeup
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.

  1. <html>  
  2.  <body>  
  3. server = $server;
  4. $this->username = $username;
  5. $this->password = $password;
  6. $this->db = $db;
  7. $this->connect();
  8. }
  9. private function connect()
  10. {
  11. $this->link = mysql_connect($this->server, $this->username, $this->password);
  12. mysql_select_db($this->db, $this->link);
  13. }
  14. public function __sleep()
  15. {
  16. return array(‘server’, ‘username’, ‘password’, ‘db’);
  17. }
  18. public function __wakeup()
  19. {
  20. $this->connect();
  21. }
  22. }
  23. ?>
  24.  </body>   
  25. </html>  
eXTReMe Tracker