3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo {} $type = 'Foo'; $args = array(); $reflection = new \ReflectionClass($type); var_dump($reflection->newInstanceArgs($args)); var_dump($reflection->newInstanceArgs(array())); var_dump($reflection->newInstanceArgs(array(2)));
based on n12IH
Output for 7.0.0 - 7.2.0
object(Foo)#2 (0) { } object(Foo)#2 (0) { } Fatal error: Uncaught ReflectionException: Class Foo does not have a constructor, so you cannot pass any constructor arguments in /in/H3WtY:12 Stack trace: #0 /in/H3WtY(12): ReflectionClass->newInstanceArgs(Array) #1 {main} thrown in /in/H3WtY on line 12
Process exited with code 255.
Output for 5.3.20 - 5.6.28
object(Foo)#2 (0) { } object(Foo)#2 (0) { } Fatal error: Uncaught exception 'ReflectionException' with message 'Class Foo does not have a constructor, so you cannot pass any constructor arguments' in /in/H3WtY:12 Stack trace: #0 /in/H3WtY(12): ReflectionClass->newInstanceArgs(Array) #1 {main} thrown in /in/H3WtY on line 12
Process exited with code 255.