我怎么知道函数的实际参数数量,
我知道func_num_args返回函数内传递的args的数量,但是外面怎么样?
function foo($x,$y)
{
// any code
}
Run Code Online (Sandbox Code Playgroud)
我怎么能动态地知道绑定到该函数的实际数量的args
i take it from SO answer : PHP function to find out the number of parameters passed into function?
func_number_args() is limited to only the function that is being called. You can't extract information about a function dynamically outside of the function at runtime.
如果您尝试在运行时提取有关函数的信息,我建议使用Reflection方法:
if(function_exists('foo'))
{
$info = new ReflectionFunction('foo');
$numberOfArgs = $info->getNumberOfParameters(); // this isn't required though
$numberOfRequiredArgs = $info->getNumberOfRequiredParameters(); // required by the function
}
Run Code Online (Sandbox Code Playgroud)