Artjom Kurapov
Artjom Kurapov

Reputation: 6155

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? Preferably without php extensions or prior code analysis (fopen...)

Upvotes: 0

Views: 255

Answers (2)

Artjom Kurapov
Artjom Kurapov

Reputation: 6155

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/

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382666

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

Upvotes: 1

Related Questions