<?php
/* sample code to describe the flow of class
when we use __sleep() and __wakeup() methods with
serilize and unserilize objects.
*/
class a
{
public $v,$vv,$vvv;
private function getTime()
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
public function __construct()
{
echo "\n".'construct '.$this->getTime();
$this->v = ' v here';
$this->vv = ' vv here';
$this->vvv = ' vvv here';
}
public function __sleep()
{
echo "\n".'sleep '.$this->getTime();
return array('v','vv');
}
public function __wakeup()
{
echo "\n".'wakeup '.$this->getTime();
$this->showall();
}
public function showall()
{
echo "\n*****\n".'showall '.$this->getTime();
echo "\n".$this->v.'--'.$this->vv.'--'.$this->vvv."\n*****\n";
}
}
// create object of class
$objA = new a();
// lets serialize the object
$objASer = serialize($objA);
echo "-\n---serialized data - ".$objASer."\n";
// lets unserialize it
$newObj = unserialize($objASer);
// letc c what happen with the first object
$objA->showall();
?>