Reputation: 66660
I'm have code that return service description object for JSON-RPC
and I have similar problem then this: PHP: Get number of parameters a function requires but instead of function I have a method.
function service_description($object) {
$class = get_class($object);
$methods = get_class_methods($class);
$service = array("sdversion" => "1.0",
"name" => "DemoService",
"address" => $_SERVER['PHP_SELF'],
"id" => "urn:md5:" . md5($_SERVER['PHP_SELF']));
foreach ($methods as $method) {
$service['procs'][] = array(
"name" => $method,
"params" => ?????
);
}
return $service;
}
How can I check parameters of each method?
Upvotes: 1
Views: 174
Reputation: 66660
I found, there is class for this ReflectionMethod.
foreach ($methods as $method_name) {
$proc = array("name" => $method_name);
$method = new ReflectionMethod($class, $method_name);
$params = array();
foreach ($method->getParameters() as $param) {
$params[] = $param->name;
}
$proc['params'] = $params;
}
Upvotes: 4
Reputation: 13545
You can still use the reflection class.
$rclass = new ReflectionClass('ClassName');
$method = $rclass->getMethod('methodName');
$method->getNumberOfRequiredParameters;
Upvotes: 1
Reputation: 722
I think you should try with this one: http://php.net/manual/en/reflectionfunctionabstract.getnumberofparameters.php
Upvotes: 0