3v4l.org

run code in 200+ PHP versions simultaneously
<?php class testClass_forSerialize implements Serializable{ public function serialize() { $ret = new \stdClass(); 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);
based on Pao0W
Output for 5.3.0 - 5.3.29, 7.0.0 - 7.4.0
Output for 5.4.14 - 5.6.28
Notice: unserialize(): Error at offset 4 of 4 bytes in /in/SggeU on line 15 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/SggeU:17 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/SggeU(13): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/SggeU(47): serialize(Object(testClass_forSerialize_02)) #4 {main} thrown in /in/SggeU on line 17
Process exited with code 255.
Output for 5.4.0 - 5.4.13
Notice: unserialize(): Error at offset 4 of 4 bytes in /in/SggeU on line 15 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/SggeU:17 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/SggeU(13): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/SggeU(47): serialize(Object(testClass_forSerialize_02)) #4 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/SggeU:13 Stack trace: #0 /in/SggeU(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/SggeU(47): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/SggeU:13 Stack trace: #0 /in/SggeU(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/SggeU(47): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a str in /in/SggeU on line 47
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 45
Output for 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 45 Fatal error: Interface 'Serializable' not found in /in/SggeU 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/SggeU on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 33 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 39 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/SggeU on line 45 Fatal error: Class 'Serializable' not found in /in/SggeU 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/SggeU 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/SggeU on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/SggeU on line 2
Process exited with code 255.