Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to dynamically check number of arguments of a function in php

Tags:

php

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
like image 411
Tibi Avatar asked Dec 06 '08 21:12

Tibi


1 Answers

You need to use reflection to do that.

$method = new ReflectionMethod('foo', 'bar');
$num = $method->getNumberOfParameters();
like image 153
Greg Avatar answered Oct 06 '22 01:10

Greg