2013-09-30 1 views
0

저는 잠시 동안이 문제를 고민했습니다. 나는 여기에 완전한 벽돌 벽을 때렸다. 방법 이름에서 메서드에 대한 정보를 수집하려고합니다. 하지만 PHP는 getMethod()에 대해 모른다. tho는 PHP에서 "reflection"의 일부가되어야한다. 이 링크에서 (http://www.php.net/manual/en/reflectionclass.getmethod.php) 는하지만에 응답 없음으로, 내 경우 것 같다 오류를 던질거야 언급이 친구 ... 내 경우에는-> getMethod ("")가 "정의되지 않은 메소드"를 던졌습니다.

코드는 다음과 같습니다

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

와 클래스는 다음과 같습니다

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

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

} 

내가이 두려워

난 신경 쓰면 WAMP Server에 postgreSQL 플러그인을 달고있다.

+0

당신이 ReflectionClass의 모든 방법이 모든 클래스에 사용할 수 있다고 생각합니까? 그건 사실이 아니야. ReflectionClass에 대한 예제를보십시오. 그것을 인스턴스화하고, 반영하고자하는 클래스를 부여한 다음 변경을해야합니다. –

답변

3

ReflectionClass은 클래스입니다. 당신은 아무것도 정의하지 않습니다, 당신은 단지 그것을 사용 :

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

It works!

+1

나는 이것에 대해 아프다고 생각한다. – CyberFox

관련 문제