3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { public $name = "admin"; } class UserCouple implements Serializable { public $user1; public $user2; public function serialize() { return serialize(array(42, serialize(array($this->user1, $this->user2)))); } public function unserialize($serialized) { list($_, $subSerialized) = unserialize($serialized); list($this->user1, $this->user2) = unserialize($subSerialized); } } $user = new User(); $couple = new UserCouple(); $couple->user1 = $user; $couple->user2 = $user; var_dump($couple); var_dump(unserialize(serialize($couple)));
based on 8GpBl
Output for 7.3.0 - 7.3.19, 7.4.0 - 7.4.8, 8.0.0alpha1 - alpha2
object(UserCouple)#2 (2) { ["user1"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } ["user2"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } } Notice: unserialize(): Error at offset 55 of 56 bytes in /in/BXuv8 on line 20 object(UserCouple)#3 (2) { ["user1"]=> NULL ["user2"]=> NULL }
Output for 5.6.38 - 5.6.40, 7.0.6 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.31
object(UserCouple)#2 (2) { ["user1"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } ["user2"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } } object(UserCouple)#3 (2) { ["user1"]=> object(User)#4 (1) { ["name"]=> string(5) "admin" } ["user2"]=> int(42) }
Output for 7.0.0 - 7.0.5
object(UserCouple)#2 (2) { ["user1"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } ["user2"]=> object(User)#1 (1) { ["name"]=> string(5) "admin" } } object(UserCouple)#3 (2) { ["user1"]=> object(User)#4 (1) { ["name"]=> string(5) "admin" } ["user2"]=> object(User)#4 (1) { ["name"]=> string(5) "admin" } }