How to check that a class method requires a parameter
1 answer
You can do it with reflection :
class Foo {
function Bar($a) {
}
}
$rc = new ReflectionClass('Foo');
$rm = $rc->getMethod('Bar');
var_dump($rm->getNumberOfRequiredParameters()); // 1
However, just because you can do it doesn't mean you should. There may be reasons for the need to verify the method signature at runtime, but in most cases you should not base your application logic on this information.
+6
source to share