3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A extends \ArrayObject { protected $foo; public function __construct() { $this->foo = 'bar'; } public function serialize() { unset($this->foo); $result = parent::serialize(); $this->foo = 'bar'; return $result; } } $a = new A(); $a->append('item1'); $a->append('item2'); $a->append('item3'); $b = new A(); echo 'Serialized string: ' . $a->serialize() . PHP_EOL; $b->unserialize($a->serialize()); var_dump($b); ?>
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Deprecated: Return type of A::serialize() should either be compatible with ArrayObject::serialize(): string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/v353G on line 11 Serialized string: x:i:0;a:3:{i:0;s:5:"item1";i:1;s:5:"item2";i:2;s:5:"item3";};m:a:0:{} object(A)#2 (2) { ["foo":protected]=> string(3) "bar" ["storage":"ArrayObject":private]=> array(3) { [0]=> string(5) "item1" [1]=> string(5) "item2" [2]=> string(5) "item3" } }
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Serialized string: x:i:0;a:3:{i:0;s:5:"item1";i:1;s:5:"item2";i:2;s:5:"item3";};m:a:0:{} object(A)#2 (2) { ["foo":protected]=> string(3) "bar" ["storage":"ArrayObject":private]=> array(3) { [0]=> string(5) "item1" [1]=> string(5) "item2" [2]=> string(5) "item3" } }

preferences:
177.68 ms | 404 KiB | 226 Q