3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.6.0 - 7.2.6
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.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.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.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