3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A extends SplObjectStorage { protected $b; protected $a = [ 'date' => null, ]; public function __construct(B $b) { $this->b = $b; $this->a = [ 'date' => '123', ]; } public function getA() { return $this->a; } } class B{} $serialized = serialize(new A(new B)); $obj = unserialize($serialized); /*$reader = function & ($object, $property) { $value = & \Closure::bind(function & () use ($property) { return $this->$property; }, $object, $object)->__invoke(); return $value; };*/ //$test3 = & $reader($obj, 'a'); echo "Result from Getter\n"; var_dump($obj->getA()); /*echo "Result from Reflection\n"; var_Dump($test3);*/ echo "This is the deserialized Object\n"; var_Dump($obj); var_Dump($obj['date']);
based on aIvvF
Output for 5.5.0 - 5.6.28, 7.0.6 - 7.3.0beta1
Result from Getter array(1) { ["date"]=> string(3) "123" } This is the deserialized Object object(A)#1 (3) { ["b":protected]=> object(B)#2 (0) { } ["a":protected]=> array(1) { ["date"]=> string(3) "123" } ["storage":"SplObjectStorage":private]=> array(0) { } } Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, string given in /in/Mgd4t on line 48 NULL
Output for 7.0.0 - 7.0.5
Result from Getter array(1) { ["date"]=> NULL } This is the deserialized Object object(A)#1 (3) { ["b":protected]=> object(B)#2 (0) { } ["a":protected]=> array(1) { ["date"]=> string(3) "123" } ["storage":"SplObjectStorage":private]=> array(0) { } } Warning: SplObjectStorage::offsetGet() expects parameter 1 to be object, string given in /in/Mgd4t on line 48 NULL