2013-09-30 37 views
0

我一直在這個問題一段時間了。我在這裏碰到了一堵完整的磚牆。我試圖從方法名稱收集有關方法的信息。但PHP不知道getMethod()這應該是PHP的「反射」的一部分。 (http://www.php.net/manual/en/reflectionclass.getmethod.php) 在鏈接有這哥們兒提它會拋出一個錯誤,這似乎是我的情況,但上面沒有答案......- > getMethod(「」)拋出「未定義的方法」

在我的情況

的代碼如下所示:

$params = $controllerInstance->getMethod($methodName)->getParameters(); 

和類看起來是這樣的:

class accountController extends controller{ 

    public function createUser(account $accountModelInstance){ 
     return "this is a response!"; 
    } 

} 

我擔心這個:

class accountController extends controller{ 
    public function getMethod(string method){ 
     return this->{method}; 
    } 
} 

如果你關心,我正在運行帶有postgreSQL插件的WAMP Server

+0

你認爲在ReflectionClass所有的方法都適用於所有類別?事實並非如此。查看ReflectionClass的示例。你必須實例化它,給它想要反思的課程,然後進行修改。 –

回答

3

ReflectionClass是一類。你不定義任何東西,你只需要使用它:

$class = new ReflectionClass($controllerInstance); 
$params = $class->getMethod($methodName)->getParameters(); 

It works!

+1

我覺得不適應這一點。 – CyberFox

相關問題