如何在类中调用该方法之前计算方法的参数?

时间:2012-12-12 19:52:27

标签: php

我的问题非常像这一个:PHP: Get argument count

除了我需要计算方法的参数(参数,如果你愿意),但这个方法在一个对象内。

我试过这个:

    $reflection = new ReflectionFunction($_SITE,$acao);
    $qtdArgumentos = $reflection->getNumberOfParameters();

和此:

    $reflection = new ReflectionFunction($_SITE->$acao);
    $qtdArgumentos = $reflection->getNumberOfParameters();

并收到此错误:

Fatal error: Uncaught exception 'ReflectionException' with message 'Function $_SITE,$acao() does not exist' in C:\wamp\www\project\index.php:20 
Stack trace: 
#0 C:\wamp\www\project\index.php(20): ReflectionFunction->__construct('$_SITE,$acao') 
#1 {main} thrown in C:\wamp\www\projeto\index.php on line 20

有没有人知道另一种计算方法参数数量的方法是在对象内部还是为我的代码解决方法?

1 个答案:

答案 0 :(得分:2)

我认为您需要的是ReflectionMethod

 $reflection = new ReflectionMethod($_SITE, $acao);
 $qtdArgumentos = $reflection->getNumberOfParameters();