<?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));
You have javascript disabled. You will not be able to edit any code.