Reputation: 461
How can i know the actual number of param the function has,
i know that func_num_args return the number of passed args inside the function but what about outside ???
function foo($x,$y)
{
// any code
}
how can i know dynamically the real num of args that bind to that function
Upvotes: 1
Views: 93
Reputation: 125466
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.
If you're attempting to extract information about a function at runtime, I recommend the Reflection approach:
if(function_exists('foo'))
{
$info = new ReflectionFunction('foo');
$numberOfArgs = $info->getNumberOfParameters(); // this isn't required though
$numberOfRequiredArgs = $info->getNumberOfRequiredParameters(); // required by the function
}
Upvotes: 8