- serialize: documentation ( source)
<?php
class Foo {
private $id = 123;
public function __construct($id) {
$this->id = $id;
}
public function getID() {
return $this->id;
}
}
class Bar extends Foo {
private $what = 'running';
private $sleeping = 3;
public function __sleep() {
return array('sleeping');
}
public function __wakeup() {
$this->what = 'awake';
}
}
$x = new Foo(42);
echo serialize($x) . "\n";
$y = new Bar(42);
echo serialize($y);