3v4l.org

run code in 300+ PHP versions simultaneously
<?php $classNames = array("StdClass", "ArrayObject", "SplFileObject"); foreach($classNames as $className) { var_dump(instanitateWithoutConstructorThroughUnserialize($className)); var_dump(instanitateWithoutConstructorThroughReflection($className)); } function instanitateWithoutConstructorThroughUnserialize($className) { return unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className)); } function instanitateWithoutConstructorThroughReflection($className) { $ref = new ReflectionClass($className); return $ref->newInstanceWithoutConstructor(); }
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Fatal error: Uncaught UnexpectedValueException: Incomplete or ill-typed serialization data in /in/HrdHY:10 Stack trace: #0 [internal function]: ArrayObject->__unserialize(Array) #1 /in/HrdHY(10): unserialize('O:11:"ArrayObje...') #2 /in/HrdHY(5): instanitateWithoutConstructorThroughUnserialize('ArrayObject') #3 {main} thrown in /in/HrdHY on line 10
Process exited with code 255.
Output for 7.3.32 - 7.3.33
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/HrdHY on line 10 bool(false) object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/HrdHY on line 10 bool(false) object(SplFileObject)#2 (1) { ["pathName":"SplFileInfo":private]=> string(0) "" }
Output for 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/HrdHY on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/HrdHY on line 10 bool(false) object(ArrayObject)#1 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Warning: Erroneous data format for unserializing 'SplFileObject' in /in/HrdHY on line 10 Notice: unserialize(): Error at offset 24 of 25 bytes in /in/HrdHY on line 10 bool(false) object(SplFileObject)#2 (1) { ["pathName":"SplFileInfo":private]=> string(0) "" }
Output for 5.4.0 - 5.4.28, 5.4.30 - 5.4.45, 5.5.0 - 5.5.12, 5.5.14 - 5.5.38
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } object(ArrayObject)#2 (1) { ["storage":"ArrayObject":private]=> array(0) { } } Fatal error: Uncaught exception 'ReflectionException' with message 'Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor' in /in/HrdHY:15 Stack trace: #0 /in/HrdHY(15): ReflectionClass->newInstanceWithoutConstructor() #1 /in/HrdHY(6): instanitateWithoutConstructorThroughReflection('ArrayObject') #2 {main} thrown in /in/HrdHY on line 15
Process exited with code 255.
Output for 5.4.29, 5.5.13
object(stdClass)#1 (0) { } object(stdClass)#2 (0) { } Warning: Erroneous data format for unserializing 'ArrayObject' in /in/HrdHY on line 10 Notice: unserialize(): Error at offset 22 of 23 bytes in /in/HrdHY on line 10 bool(false) Fatal error: Uncaught exception 'ReflectionException' with message 'Class ArrayObject is an internal class that cannot be instantiated without invoking its constructor' in /in/HrdHY:15 Stack trace: #0 /in/HrdHY(15): ReflectionClass->newInstanceWithoutConstructor() #1 /in/HrdHY(6): instanitateWithoutConstructorThroughReflection('ArrayObject') #2 {main} thrown in /in/HrdHY on line 15
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
object(stdClass)#1 (0) { } Fatal error: Call to undefined method ReflectionClass::newInstanceWithoutConstructor() in /in/HrdHY on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
object(stdClass)(0) { } Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/HrdHY on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1
object(stdClass)(0) { } Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/HrdHY on line 14

preferences:
252.4 ms | 401 KiB | 358 Q