3v4l.org

run code in 300+ PHP versions simultaneously
<?php # base class class Test_TestClassBase { public $x = 4; public function __wakeup() { var_dump("__wakeup"); } public function __sleep() { var_dump("__sleep"); return array_keys(get_object_vars($this)); } public function unserialize($input) { var_dump("unserialize"); } public function serialize() { var_dump("serialize"); return serialize(get_object_vars($this)); } } # derived classes class Test_TestClassA extends Test_TestClassBase {} class Test_TestClassB extends Test_TestClassBase implements Serializable {} class Test_TestClassAA extends Test_TestClassA implements Serializable {} class Test_TestClassBB extends Test_TestClassB {} # run our serialisation foreach(array("Test_TestClassA", "Test_TestClassB", "Test_TestClassAA", "Test_TestClassBB") as $class) { $serialised = 'O:'.strlen($class).':"'.$class.'":1:{s:1:"x";i:4;}'; var_dump("(input) ".$serialised); var_dump("(output) ".(unserialize($serialised) instanceof $class ? "true (passing)" : "false (failing)")); }
Output for 5.4.29, 5.5.13, 5.6.0 - 5.6.30, 7.0.0 - 7.0.30, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.26, 7.4.0 - 7.4.14, 8.0.0
string(48) "(input) O:15:"Test_TestClassA":1:{s:1:"x";i:4;}" string(8) "__wakeup" string(23) "(output) true (passing)" string(48) "(input) O:15:"Test_TestClassB":1:{s:1:"x";i:4;}" Warning: Erroneous data format for unserializing 'Test_TestClassB' in /in/XRr5t on line 48 Notice: unserialize(): Error at offset 26 of 39 bytes in /in/XRr5t on line 48 string(24) "(output) false (failing)" string(49) "(input) O:16:"Test_TestClassAA":1:{s:1:"x";i:4;}" Warning: Erroneous data format for unserializing 'Test_TestClassAA' in /in/XRr5t on line 48 Notice: unserialize(): Error at offset 27 of 40 bytes in /in/XRr5t on line 48 string(24) "(output) false (failing)" string(49) "(input) O:16:"Test_TestClassBB":1:{s:1:"x";i:4;}" Warning: Erroneous data format for unserializing 'Test_TestClassBB' in /in/XRr5t on line 48 Notice: unserialize(): Error at offset 27 of 40 bytes in /in/XRr5t on line 48 string(24) "(output) false (failing)"
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.28, 5.4.30 - 5.4.45, 5.5.0 - 5.5.12, 5.5.14 - 5.5.38
string(48) "(input) O:15:"Test_TestClassA":1:{s:1:"x";i:4;}" string(8) "__wakeup" string(23) "(output) true (passing)" string(48) "(input) O:15:"Test_TestClassB":1:{s:1:"x";i:4;}" string(8) "__wakeup" string(23) "(output) true (passing)" string(49) "(input) O:16:"Test_TestClassAA":1:{s:1:"x";i:4;}" string(8) "__wakeup" string(23) "(output) true (passing)" string(49) "(input) O:16:"Test_TestClassBB":1:{s:1:"x";i:4;}" string(8) "__wakeup" string(23) "(output) true (passing)"
Output for 5.0.5
Fatal error: Interface 'Serializable' not found in /in/XRr5t on line 37
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'Serializable' not found in /in/XRr5t on line 37
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XRr5t on line 7
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 T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XRr5t on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/XRr5t on line 7
Process exited with code 255.