3v4l.org

run code in 300+ PHP versions simultaneously
<?php $classNames = array( "Foo", // userland class "StdClass", // class defined by php-src, but still not considered as internal "ReflectionClass", // internal class "ArrayObject", // internal class implementing Serializable ); foreach($classNames as $className) { var_dump(instanitateWithoutConstructorThroughUnserialize($className)); if (version_compare(PHP_VERSION, '5.3.0') > 0) { var_dump(instanitateWithoutConstructorThroughReflection($className)); } } function instanitateWithoutConstructorThroughUnserialize($className) { return unserialize(sprintf('O:%d:"%s":0:{}', strlen($className), $className)); } function instanitateWithoutConstructorThroughReflection($className) { try { $ref = new ReflectionClass($className); return $ref->newInstanceWithoutConstructor(); } catch (ReflectionException $e) { return $e; } } class Foo {}
Output for git.master, git.master_jit, rfc.property-hooks
object(Foo)#1 (0) { } object(Foo)#2 (0) { } object(stdClass)#2 (0) { } object(stdClass)#1 (0) { } Fatal error: Uncaught Exception: Unserialization of 'ReflectionClass' is not allowed in /in/o08hk:18 Stack trace: #0 /in/o08hk(18): unserialize('O:15:"Reflectio...') #1 /in/o08hk(11): instanitateWithoutConstructorThroughUnserialize('ReflectionClass') #2 {main} thrown in /in/o08hk on line 18
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.03 ms | 401 KiB | 8 Q