3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class B { const name = 'awk'; public $name = 'awk'; function test() { echo __FUNCTION__ . '\n'; } } class Test { function test1(B $a, $b) { var_dump($a, $b); } } $method = 'test1'; $class = new ReflectionClass('Test'); $test1 = $class->getMethod($method); $args = $test1->getParameters(); $args_arr = []; foreach ($args as $arg) { $reflection_class = $arg->getClass(); if ($reflection_class) { $arg = $reflection_class->newInstance(); } $args_arr[] = $arg; } call_user_func_array([new Test(), $method], $args_arr); //var_dump($args_arr);
based on VpJmf
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0rc3
object(B)#6 (1) { ["name"]=> string(3) "awk" } object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "b" }
Output for hhvm-3.15.4
object(B)#6 (1) { ["name"]=> string(3) "awk" } object(ReflectionParameter)#4 (3) { ["info"]=> array(11) { ["index"]=> int(1) ["name"]=> string(1) "b" ["type"]=> string(0) "" ["type_hint"]=> string(0) "" ["type_hint_builtin"]=> bool(false) ["function"]=> string(5) "test1" ["class"]=> string(4) "Test" ["nullable"]=> bool(true) ["type_hint_nullable"]=> bool(true) ["attributes"]=> array(0) { } ["is_optional"]=> bool(false) } ["name"]=> string(1) "b" ["paramTypeInfo"]=> array(3) { ["name"]=> string(0) "" ["nullable"]=> bool(true) ["builtin"]=> bool(false) } }