3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements \Serializable { public $default = 10; public $setMe; private $test = 1; public $removeOnSerialize = 'blah'; public function serialize() { unset($this->removeOnSerialze); return serialize($this->getData()); } public function unserialize($serialized) { foreach (unserialize($serialized) as $key => $value) { $this->$key = $value; } $this->removeOnSerialize = 'Set some value'; } protected function getData() { return (array)$this; } } $obj = new Foo(); $obj->setMe = 9999; print_r($obj); // here I have all as exepcted $serialized = serialize($obj); $unserialized = unserialize($serialized); print_r($unserialized);

preferences:
62.96 ms | 402 KiB | 5 Q