3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/H5Msq on line 31 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/H5Msq on line 31 object(B)#6 (1) { ["name"]=> string(3) "awk" } object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "b" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/H5Msq on line 31 Deprecated: Method ReflectionParameter::getClass() is deprecated in /in/H5Msq on line 31 object(B)#6 (1) { ["name"]=> string(3) "awk" } object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "b" }
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
object(B)#6 (1) { ["name"]=> string(3) "awk" } object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "b" }

preferences:
215.03 ms | 403 KiB | 291 Q