3v4l.org

run code in 300+ 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; } } /* $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);
based on RGDCi
Output for 5.3.0 - 5.3.29, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.27, 7.4.0 - 7.4.15, 8.0.0 - 8.0.3
Output for 5.4.14 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Notice: unserialize(): Error at offset 4 of 4 bytes in /in/Pao0W on line 25 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/Pao0W:27 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/Pao0W(23): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/Pao0W(57): serialize(Object(testClass_forSerialize_02)) #4 {main} thrown in /in/Pao0W on line 27
Process exited with code 255.
Output for 5.4.0 - 5.4.13
Notice: unserialize(): Error at offset 4 of 4 bytes in /in/Pao0W on line 25 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/Pao0W:27 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/Pao0W(23): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/Pao0W(57): serialize(Object(testClass_forSerialize_02)) #4 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/Pao0W:23 Stack trace: #0 /in/Pao0W(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/Pao0W(57): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/Pao0W:23 Stack trace: #0 /in/Pao0W(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/Pao0W(57): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a str in /in/Pao0W on line 57
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 55
Output for 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 55 Fatal error: Interface 'Serializable' not found in /in/Pao0W 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/Pao0W on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Pao0W on line 55 Fatal error: Class 'Serializable' not found in /in/Pao0W 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/Pao0W on line 2
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/Pao0W on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/Pao0W on line 2
Process exited with code 255.