<?php
class Sleep
{

  public $greeting = 'Hello, world!';

  public function __sleep()
  {
    echo 'Going to sleep!' . PHP_EOL;
    return array('greeting');
  }

  public function __wakeup()
  {
    echo $this->connect();
  }

  public function connect()
  {
    echo 'Wake up!' . PHP_EOL;
    echo $this->greeting . PHP_EOL;
  }

}

$obj = new Sleep();
$serialize = serialize($obj);
unserialize($serialize);
?>
Published in: PHP
Download

Related snippets