3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.4.39 - 5.6.28, 7.0.6 - 7.1.0
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.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.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.