3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ObjectWithReferences { protected $var1; protected $var2; public function __construct() { $this->var1 = new StdClass(); $this->var2 = $this->var1; } } class WrapperObject implements Serializable { private $obj; public function __construct($obj) { $this->obj = $obj; } public function getObject() { return $this->obj; } public function serialize() { for ($i = 0; $i < 10; ++$i) { var_dump(serialize(new \stdClass())); } return serialize($this->obj); } public function unserialize($serialized) { $this->obj = unserialize($serialized); } } $wrapper = new WrapperObject(new ObjectWithReferences()); var_dump($wrapper->getObject()); $serialized = serialize($wrapper); var_dump($serialized); $wrapper = unserialize($serialized);
Output for 8.3.0 - 8.3.6
Deprecated: WrapperObject implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/lUC11 on line 13 object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}" Warning: unserialize(): Error at offset 83 of 84 bytes in /in/lUC11 on line 34
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Deprecated: WrapperObject implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/lUC11 on line 13 object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}" Notice: unserialize(): Error at offset 83 of 84 bytes in /in/lUC11 on line 34
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}" Notice: unserialize(): Error at offset 83 of 84 bytes in /in/lUC11 on line 34
Output for 7.3.32 - 7.3.33
object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}"
Output for 5.4.22 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(19) "O:8:"stdClass":0:{}" string(4) "r:2;" string(4) "r:3;" string(4) "r:4;" string(4) "r:2;" string(4) "r:3;" string(4) "r:4;" string(4) "r:2;" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}" Notice: unserialize(): Error at offset 83 of 84 bytes in /in/lUC11 on line 34
Output for 5.4.1 - 5.4.21
object(ObjectWithReferences)#2 (2) { ["var1":protected]=> object(stdClass)#3 (0) { } ["var2":protected]=> object(stdClass)#3 (0) { } } string(19) "O:8:"stdClass":0:{}" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(4) "r:2;" string(110) "C:13:"WrapperObject":84:{O:20:"ObjectWithReferences":2:{s:7:"*var1";O:8:"stdClass":0:{}s:7:"*var2";r:13;}}" Notice: unserialize(): Error at offset 83 of 84 bytes in /in/lUC11 on line 34

preferences:
196.32 ms | 402 KiB | 229 Q