我正在阅读有关php ReflectionFunction
的信息。是否可以使用它来检查类方法的各种参数的类型?
你必须使用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";
}
但是:ぁzxswい
您可以使用以下解决方案来获取所有方法的所有参数,使用https://ideone.com/uBUghi:
ReflectionClass
但是:ぁzxswい