3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait DependencySerializationTrait { public function __sleep() { return array_keys(get_object_vars($this)); } } abstract class Base { use DependencySerializationTrait; } class Test extends Base { private $something; public function __construct() { $this->something = 'test'; } public function getSomething() { return $this->something ?? 'NULLSAD'; } } class TestV2 { private $something; public function __construct() { $this->something = 'yay!'; } public function getSomething() { return $this->something ?? 'NULLSAD'; } public function __sleep() { return array_keys(get_object_vars($this)); } } $foo = new Test(); $blob = serialize($foo); $un_foo = unserialize($blob); echo $un_foo->getSomething(); echo "\n"; $bar = new TestV2(); $blob = serialize($bar); $un_bar = unserialize($blob); echo $un_bar->getSomething();

preferences:
34.61 ms | 407 KiB | 5 Q