tags:

views:

59

answers:

1

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

+8  A: 

i take it from SO answer : http://stackoverflow.com/questions/2811445/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

}
Haim Evgi
A small correction $info->getParameters(); is all what i dream of
S.Hawary