Tutorial :PHP function actual params


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


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    }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »