Nandakumar V
Nandakumar V

Reputation: 4615

PHP: Get the number of parameter a function accepts

Is there any method for finding the number of parameters a php function will accept, Like

pow - 2   
strlen - 2   
sqrt - 1   

I have dome some research and got to ReflectionFunctionAbstract::getNumberOfParameters. But it seems ReflectionMethod needs a class and a method. Here i don't have a class object.

Also I cannot use func_num_args method since for that I have to be inside the method, which is not possible.

Upvotes: 0

Views: 54

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

Try it, this may meet your requirements...

 $info = new ReflectionFunction('sqrt');
 #print $info->getNumberOfRequiredParameters();
var_dump(
  $info->getName(),
  $info->getNumberOfParameters(),
  $info->getNumberOfRequiredParameters()
);

Upvotes: 1

Related Questions