3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo {} class Bar { public function __construct($param1) {} } $reflection = new \ReflectionClass('Foo'); var_dump($reflection->newInstanceArgs(array())); try { var_dump($reflection->newInstanceArgs(array(1))); } catch (Exception $e) { echo $e; } $reflectionB = new \ReflectionClass('Bar'); var_dump($reflectionB->newInstanceArgs(array())); var_dump($reflectionB->newInstanceArgs(array(1))); var_dump($reflectionB->newInstanceArgs(array(1,2))); class FooBar extends Bar {} $reflection = new \ReflectionClass('FooBar'); var_dump($reflection->newInstanceArgs(array())); try { var_dump($reflection->newInstanceArgs(array(1))); } catch (Exception $e) { echo $e; }
based on jM8ph
Output for 7.1.0 - 7.2.0
object(Foo)#2 (0) { } ReflectionException: Class Foo does not have a constructor, so you cannot pass any constructor arguments in /in/Av9GT:11 Stack trace: #0 /in/Av9GT(11): ReflectionClass->newInstanceArgs(Array) #1 {main} Fatal error: Uncaught ArgumentCountError: Too few arguments to function Bar::__construct(), 0 passed and exactly 1 expected in /in/Av9GT:5 Stack trace: #0 [internal function]: Bar->__construct() #1 /in/Av9GT(17): ReflectionClass->newInstanceArgs(Array) #2 {main} thrown in /in/Av9GT on line 5
Process exited with code 255.
Output for 7.0.0 - 7.0.20
object(Foo)#2 (0) { } ReflectionException: Class Foo does not have a constructor, so you cannot pass any constructor arguments in /in/Av9GT:11 Stack trace: #0 /in/Av9GT(11): ReflectionClass->newInstanceArgs(Array) #1 {main} Warning: Missing argument 1 for Bar::__construct() in /in/Av9GT on line 5 object(Bar)#4 (0) { } object(Bar)#4 (0) { } object(Bar)#4 (0) { } Warning: Missing argument 1 for Bar::__construct() in /in/Av9GT on line 5 object(FooBar)#1 (0) { } object(FooBar)#1 (0) { }
Output for 5.3.4 - 5.6.28
object(Foo)#2 (0) { } exception 'ReflectionException' with message 'Class Foo does not have a constructor, so you cannot pass any constructor arguments' in /in/Av9GT:11 Stack trace: #0 /in/Av9GT(11): ReflectionClass->newInstanceArgs(Array) #1 {main} Warning: Missing argument 1 for Bar::__construct() in /in/Av9GT on line 5 object(Bar)#4 (0) { } object(Bar)#4 (0) { } object(Bar)#4 (0) { } Warning: Missing argument 1 for Bar::__construct() in /in/Av9GT on line 5 object(FooBar)#1 (0) { } object(FooBar)#1 (0) { }
Output for 5.3.0 - 5.3.3
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Foo does not have a constructor, so you cannot pass any constructor arguments' in /in/Av9GT:9 Stack trace: #0 /in/Av9GT(9): ReflectionClass->newInstanceArgs(Array) #1 {main} thrown in /in/Av9GT on line 9
Process exited with code 255.
Output for 5.1.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 25 Fatal error: Uncaught exception 'ReflectionException' with message 'Class Foo does not have a constructor, so you cannot pass any constructor arguments' in /in/Av9GT:9 Stack trace: #0 /in/Av9GT(9): ReflectionClass->newInstanceArgs(Array) #1 {main} thrown in /in/Av9GT on line 9
Process exited with code 255.
Output for 5.0.0 - 5.1.2
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 8 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/Av9GT on line 25 Fatal error: Call to undefined method ReflectionClass::newInstanceArgs() in /in/Av9GT on line 9
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/Av9GT on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/Av9GT on line 5
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/Av9GT on line 5
Process exited with code 255.