3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Widget implements Serializable { public $references = array(); public $config; public function serialize() { $vars = get_object_vars($this); $vars['config'] = serialize($vars['config']); $serialized = serialize($vars); return $serialized; } public function unserialize($serialized) { $array = unserialize($serialized); $array['config'] = unserialize($array['config']); foreach($array as $k => $v) { $this->$k = $v; } } } class Placeholder { public $id; public function __construct($id) { $this->id = $id; } } $collection = array(); $placeholder1 = new Placeholder(1); $placeholder2 = new Placeholder(2); $widget1 = new Widget; $widget1->config = array('id_section' => 9); $widget1->references[] = $placeholder1; $widget2 = new Widget; $widget2->config = array('id_section' => 9); $widget2->references[] = $placeholder2; $widget3 = new Widget; $widget3->config = array('id_section' => 9); $widget3->references[] = $placeholder1; $widget4 = new Widget; $widget4->config = array('id_section' => 9); $widget4->references[] = $placeholder1; $collection[] = $widget1; $collection[] = $widget2; $collection[] = $widget3; // reference to placeholder will be missing here $collection[] = $widget4; // reference to placeholder will be missing here print_r(unserialize(serialize($collection)));
Output for 8.3.0 - 8.3.6
Deprecated: Widget 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/FjJmf on line 3 Warning: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on false in /in/FjJmf on line 23 Deprecated: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in /in/FjJmf on line 23 Deprecated: Automatic conversion of false to array is deprecated in /in/FjJmf on line 23 Warning: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on false in /in/FjJmf on line 23 Deprecated: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in /in/FjJmf on line 23 Deprecated: Automatic conversion of false to array is deprecated in /in/FjJmf on line 23 Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Deprecated: Widget 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/FjJmf on line 3 Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Deprecated: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in /in/FjJmf on line 23 Deprecated: Automatic conversion of false to array is deprecated in /in/FjJmf on line 23 Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Deprecated: unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in /in/FjJmf on line 23 Deprecated: Automatic conversion of false to array is deprecated in /in/FjJmf on line 23 Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 8.0.0 - 8.0.30
Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Warning: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Notice: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Notice: Trying to access array offset on value of type bool in /in/FjJmf on line 23 Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 7.3.32 - 7.3.33, 7.4.26
Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 7.3.0 - 7.3.31
Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Notice: unserialize(): Error at offset 36 of 87 bytes in /in/FjJmf on line 21 Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( ) [config] => ) [3] => Widget Object ( [references] => Array ( ) [config] => ) )
Output for 5.4.39 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.6 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( [0] => a:1:{s:10:"id_section";i:9;} ) [config] => Array ( [id_section] => 9 ) ) [3] => Widget Object ( [references] => Array ( [0] => a:1:{s:10:"id_section";i:9;} ) [config] => Array ( [id_section] => 9 ) ) )
Output for 7.0.0 - 7.0.5
Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( [0] => Array ( [id_section] => 9 ) ) [config] => Array ( [id_section] => 9 ) ) [3] => Widget Object ( [references] => Array ( [0] => Array ( [id_section] => 9 ) ) [config] => Array ( [id_section] => 9 ) ) )
Output for 5.4.0 - 5.4.38
Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( [0] => Widget Object *RECURSION* ) [config] => Array ( [id_section] => 9 ) ) [3] => Widget Object ( [references] => Array ( [0] => Widget Object ( [references] => Array ( [0] => Widget Object *RECURSION* ) [config] => Array ( [id_section] => 9 ) ) ) [config] => Array ( [id_section] => 9 ) ) )
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Array ( [0] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [1] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 2 ) ) [config] => Array ( [id_section] => 9 ) ) [2] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) [3] => Widget Object ( [references] => Array ( [0] => Placeholder Object ( [id] => 1 ) ) [config] => Array ( [id_section] => 9 ) ) )
Output for 5.0.5
Fatal error: Interface 'Serializable' not found in /in/FjJmf on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'Serializable' not found in /in/FjJmf on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/FjJmf on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/FjJmf on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/FjJmf on line 3
Process exited with code 255.

preferences:
253.87 ms | 401 KiB | 330 Q