Reputation: 137
how can I check at runtime home many parameters a method or a function have in PHP.
example
class foo { function bar ( arg1, arg2 ){ ..... } }
I will need to know if there is a way to run something like
get_func_arg_number ( "foo", "bar" )
and the result to be
2
Upvotes: 12
Views: 5949
Reputation: 321864
You need to use reflection to do that.
$method = new ReflectionMethod('foo', 'bar');
$num = $method->getNumberOfParameters();
Upvotes: 31
Reputation: 166166
Reflection is what you're after here
class foo {
function bar ( $arg1, $arg2 ){
}
}
$ReflectionFoo = new ReflectionClass('foo');
echo $ReflectionFoo->getMethod('bar')->getNumberOfParameters();
Upvotes: 9
Reputation: 6228
I believe you are looking for func_num_args()
https://www.php.net/manual/en/function.func-num-args.php
Upvotes: -5