Val
Val

Reputation: 17522

check params required in php

is there a way to find out how many parameters/arguments does the function expect?

lets say

function foo($par,$bar=false){
   ...
}


//fictional function below
echo numbr_of_params('foo'); // should return 1// as $bar is optional :)

Upvotes: 0

Views: 175

Answers (3)

nickf
nickf

Reputation: 546045

You'd have to use the Reflection functions in PHP, such as ReflectionFunction, especially ReflectionFunction::getParameters

Upvotes: 0

Mārtiņš Briedis
Mārtiņš Briedis

Reputation: 17762

Try function reflections: http://lv.php.net/manual/en/class.reflectionfunction.php

Upvotes: 0

akond
akond

Reputation: 16035

    $reflection = new ReflectionFunction($function_name);
    $reflection->getNumberOfParameters();
    $reflection->getNumberOfRequiredParameters();

Upvotes: 1

Related Questions