如何在运行时回家查看PHP中方法或函数的许多参数.
例
class foo { function bar ( arg1, arg2 ){ ..... } }
我需要知道是否有办法运行类似的东西
get_func_arg_number ( "foo", "bar" )
结果是
2
Gre*_*reg 29
你需要使用反射来做到这一点.
$method = new ReflectionMethod('foo', 'bar');
$num = $method->getNumberOfParameters();
Run Code Online (Sandbox Code Playgroud)
反思就是你在这里所追求的
class foo {
function bar ( $arg1, $arg2 ){
}
}
$ReflectionFoo = new ReflectionClass('foo');
echo $ReflectionFoo->getMethod('bar')->getNumberOfParameters();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4932 次 |
最近记录: |