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

1 Answer 1

8

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

}
Sign up to request clarification or add additional context in comments.

1 Comment

A small correction $info->getParameters(); is all what i dream of

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.