获取类方法参数类型

问题描述 投票:1回答:1

我正在阅读有关php ReflectionFunction的信息。是否可以使用它来检查类方法的各种参数的类型?

php oop
1个回答
1
投票

你必须使用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い

© www.soinside.com 2019 - 2024. All rights reserved.