I know:
function params($fn) {
$R = new ReflectionFunction($fn);
return $R->getNumberOfParameters();
}
returns the number of parameters the function can accept, but how do I do this for a method that exists in a class?
I know:
function params($fn) {
$R = new ReflectionFunction($fn);
return $R->getNumberOfParameters();
}
returns the number of parameters the function can accept, but how do I do this for a method that exists in a class?
You can for instance add a new parameter $clazz to your function, in order to give a scope to the method you want to know the number of arguments. Instead of using ReflectionFunction, use ReflectionClass in addition with ReflectionMethod.
function params($clazz, $method) {
$C = new ReflectionClass($clazz);
$M = $C->getMethod($method);
return $M->getNumberOfParameters();
}