- unserialize: documentation ( source)
- var_export: documentation ( source)
- serialize: documentation ( source)
- array_keys: documentation ( source)
- get_object_vars: documentation ( source)
<?php
class F {
private string $bar;
public function __construct(private string $foo, string $bar){
$this->bar = $bar;
}
public function __sleep(): array {
return array_keys(get_object_vars($this));
}
public function getFoo():string {
return $this->foo;
}
public function getBar():string {
return $this->bar;
}
}
$g = new F('this is a private variable', 'so is this');
class G extends F {}
$s = serialize($g);
var_export($s);
$n = unserialize($s);
echo \PHP_EOL;
echo $n->getFoo();
echo \PHP_EOL;
echo $n->getBar();
$h = new G('This is an extension', 'of the other one');
$s = serialize($h);
echo \PHP_EOL;
var_export($s);
$n = unserialize($s);
echo \PHP_EOL;
echo $n->getFoo();
echo \PHP_EOL;
echo $n->getBar();