__wakeup() method

__wakeup() is a magic method : it is called an object is being deserialized, so that the object may be restored to its working condition.

In particular, some resources, such as database connections or files cannot be serialized. They should be closed, stored as a path in __sleep(), and reopened later with __wakeup().

The __wakeup() method is usually paired with the __sleep() method.

<?php

class x {
     private $file;
     private $path;

     function __sleep() {
             fclose($this->path);
     }

     function __wakeup() {
             $this->path = fopen($this->path, 'r');
     }
}

?>

Documentation

See also PHP __sleep And __wakeup Magic Methods: How And When To Use Them?, __sleep() and __wakeup()

Related : Magic Methods, __sleep() method