3v4l.org

run code in 300+ PHP versions simultaneously
<?php class testA implements \Serializable { private $b = 123; public $a = 4; public function test() { $this->b = 1234; } public function serialize() { return serialize(array("a" => $this->a, "b" => $this->b)); } public function unserialize($str) { $ar = unserialize($str); $this->a = $ar['a']; $this->b = $ar['b']; } } $className = "testA"; $object = unserialize( sprintf('O:%d:"%s":0:{}', strlen($className), $className) ); var_dump($object);

preferences:
23.07 ms | 402 KiB | 5 Q