3v4l.org

run code in 500+ PHP versions simultaneously
<?php class P { private int $someProp = 0; public function setProp(int $value): void { $this->someProp = $value; } } class C extends P { private array $cache = []; private int $someOtherProp; public function __construct(int $value) { $this->someOtherProp = $value; } public function fillCache(): void { $this->cache[] = 'value'; } public function __serialize(): array { return [ 'someOtherProp' => $this->someOtherProp ]; } public function __unserialize(array $data): void { $this->someOtherProp = $data['someOtherProp']; $this->cache = []; } } $c = new C(7); $c->setProp(5); $c->fillCache(); var_dump($c); var_dump($s = serialize($c)); var_dump(unserialize($s));
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
object(C)#1 (3) { ["someProp":"P":private]=> int(5) ["cache":"C":private]=> array(1) { [0]=> string(5) "value" } ["someOtherProp":"C":private]=> int(7) } string(37) "O:1:"C":1:{s:13:"someOtherProp";i:7;}" object(C)#2 (3) { ["someProp":"P":private]=> int(0) ["cache":"C":private]=> array(0) { } ["someOtherProp":"C":private]=> int(7) }
Output for 8.0.1 - 8.0.30
object(C)#1 (3) { ["cache":"C":private]=> array(1) { [0]=> string(5) "value" } ["someOtherProp":"C":private]=> int(7) ["someProp":"P":private]=> int(5) } string(37) "O:1:"C":1:{s:13:"someOtherProp";i:7;}" object(C)#2 (3) { ["cache":"C":private]=> array(0) { } ["someOtherProp":"C":private]=> int(7) ["someProp":"P":private]=> int(0) }

preferences:
33.22 ms | 1141 KiB | 9 Q