Вы должны использовать класс ReflectionMethod
вместо ReflectionFunction
:
class Test {
public function Test1(int $number, string $str) { }
}
//get the information about a specific method.
$rm = new ReflectionMethod('Test', 'Test1');
//get all parameter names and parameter types of the method.
foreach ($rm->getParameters() as $parameter) {
echo 'Name: '.$parameter->getName().' - Type: '.$parameter->getType()."\n";
}
демо: https://ideone.com/uBUghi
Вы можете использовать следующее решение для получения всех параметров всех методов, используя ReflectionClass
:
class Test {
public function Test1(int $number, string $str) { }
public function Test2(bool $boolean) { }
public function Test3($value) { }
}
//get the information of the class.
$rf = new ReflectionClass('Test');
//run through all methods.
foreach ($rf->getMethods() as $method) {
echo $method->name."\n";
//run through all parameters of the method.
foreach ($method->getParameters() as $parameter) {
echo "\t".'Name: '.$parameter->getName().' - Type: '.$parameter->getType()."\n";
}
}
demo: https://ideone.com/Ac7M2L