3v4l.org

run code in 300+ PHP versions simultaneously
<?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) { var_dump($e); } $reflectionB = new \ReflectionClass('Bar'); var_dump($reflectionB->newInstanceArgs(array())); var_dump($reflectionB->newInstanceArgs(array(1))); var_dump($reflectionB->newInstanceArgs(array(1,2)));
Output for git.master, git.master_jit, rfc.property-hooks
object(Foo)#2 (0) { } object(ReflectionException)#3 (7) { ["message":protected]=> string(83) "Class Foo does not have a constructor, so you cannot pass any constructor arguments" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/bVEgs" ["line":protected]=> int(11) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(9) "/in/bVEgs" ["line"]=> int(11) ["function"]=> string(15) "newInstanceArgs" ["class"]=> string(15) "ReflectionClass" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(1) { [0]=> int(1) } } } } ["previous":"Exception":private]=> NULL } Fatal error: Uncaught ArgumentCountError: Too few arguments to function Bar::__construct(), 0 passed and exactly 1 expected in /in/bVEgs:5 Stack trace: #0 [internal function]: Bar->__construct() #1 /in/bVEgs(18): ReflectionClass->newInstanceArgs(Array) #2 {main} thrown in /in/bVEgs on line 5
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:
42.88 ms | 402 KiB | 8 Q