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 gzdeflate($serializedData, 9); } public function unserialize($data) { $dataObj = unserialize(gzinflate($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 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: testClass_forSerialize 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/RGDCi on line 2 Deprecated: testClass_forSerialize_02 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/RGDCi on line 43
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: testClass_forSerialize 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/RGDCi on line 2 Deprecated: testClass_forSerialize_02 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/RGDCi on line 43
Output for 5.3.0 - 5.3.29, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Output for 5.4.14 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Notice: unserialize(): Error at offset 4 of 4 bytes in /in/RGDCi on line 25 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/RGDCi:27 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/RGDCi(23): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/RGDCi(57): serialize(Object(testClass_forSerialize_02)) #4 {main} thrown in /in/RGDCi 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/RGDCi on line 25 string(4) "r:5;" Fatal error: Uncaught exception 'Exception' with message 'Serialize failed' in /in/RGDCi:27 Stack trace: #0 [internal function]: testClass_forSerialize->serialize() #1 /in/RGDCi(23): serialize(Object(stdClass)) #2 [internal function]: testClass_forSerialize->serialize() #3 /in/RGDCi(57): serialize(Object(testClass_forSerialize_02)) #4 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/RGDCi:23 Stack trace: #0 /in/RGDCi(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/RGDCi(57): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a string or NULL' in /in/RGDCi:23 Stack trace: #0 /in/RGDCi(0): serialize() #1 [internal function]: testClass_forSerialize->serialize() #2 /in/RGDCi(57): serialize(Object(testClass_forSerialize_02)) #3 {main} Next exception 'Exception' with message 'testClass_forSerialize::serialize() must return a str in /in/RGDCi 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/RGDCi on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 55
Output for 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 55 Fatal error: Interface 'Serializable' not found in /in/RGDCi 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/RGDCi on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 27 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 43 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 49 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/RGDCi on line 55 Fatal error: Class 'Serializable' not found in /in/RGDCi 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/RGDCi 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/RGDCi on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/RGDCi on line 2
Process exited with code 255.

preferences:
265.48 ms | 401 KiB | 456 Q