3v4l.org

run code in 200+ PHP versions simultaneously
<?php class testClass_forSerialize implements Serializable{ public function serialize() { // use array instead of stdClass $ret = Array(); foreach($this as $k=>$v){ if ($v!==null) { $ret[$k] = $v; } } $serializedData = serialize($ret); if (unserialize($serializedData)===false) { var_dump($serializedData); throw new \Exception("Serialize failed"); } return $serializedData; } public function unserialize($data) { $dataObj = unserialize($data); foreach($dataObj as $k=>$v) { $this->{$k} = $v; } } } class testClass_forSerialize_02 extends \testClass_forSerialize{ public $list = Array(); public function __construct() { for ($i=0; $i<10; $i++) { $this->list[] = new \testClass_forSerialize(); } } } $obj = new \testClass_forSerialize_02(); $ser = serialize($obj); $obj2 = unserialize($ser);
Output for 5.3.0 - 7.4.1
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 45
Output for 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 45 Fatal error: Interface 'Serializable' not found in /in/hIJE9 on line 2
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/hIJE9 on line 45 Fatal error: Class 'Serializable' not found in /in/hIJE9 on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/hIJE9 on line 2
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/hIJE9 on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/hIJE9 on line 2
Process exited with code 255.