开发者

Getting method params

Lets say I have a class like:

class SomeClass{
    function someAction($param1,$param2){}
}

Is there any way to get analyzing data like array('param1','param2') without actual execution of method? Prefera开发者_如何学编程bly without php extensions or prior code analysis (fopen...)


I think you can use the Reflection class to get info about method(s) and params.


Great, thank you all, solved it with something like

$oRuleContainer = new cRuleContainer();
$rContainer = new ReflectionClass('cRuleContainer');

$rMethod = $rContainer->getMethod($aRule['method']);
$aArgs = $rMethod->getParameters();

if($aArgs){
    foreach($aArgs as $refArgument){
        $arrPassedArgData[$refArgument->name]=$_POST[$refArgument->name];
    }
}

if(call_user_func_array(array($oRuleContainer,$aRule['method']),$arrPassedArgData)){
//success
}

More details at http://kurapov.name/rus/technology/web/php/reflection_php_brms/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜