3v4l.org

run code in 300+ PHP versions simultaneously
<?php function args_to_assoc_array($function, $args) { if (false === strpos($function, '::')) { $reflection = new ReflectionFunction($function); } else { $reflection = new ReflectionMethod(...explode('::', $function)); } $assoc = []; foreach ($reflection->getParameters() as $i => $parameter) { $assoc[$parameter->getName()] = $args[$i]; } return $assoc; } function f($x, $y) { return args_to_assoc_array(__METHOD__, func_get_args()); } class A { function m($z) { return args_to_assoc_array(__METHOD__, func_get_args()); } } var_dump(f(7, 2), (new A)->m(4));

preferences:
63.17 ms | 402 KiB | 5 Q