Controlling serialization using __sleep() and __wakeUp()
<?php
class LogFile {
protected $filename;
protected $handle;
public function __construct($filename) {
$this->filename = $filename;
$this->open();
}
private function open() {
$this->handle = fopen($this->filename, 'a');
}
public function __destruct($filename) {
fclose($this->handle);
}
public function __sleep() {
return array('filename');
}
public function __wakeUp() {
$this->open();
}
}
?>
Related examples in the same category