函数名称:ReflectionProperty::getType()
适用版本:PHP 7.4+
函数说明:ReflectionProperty::getType() 方法用于获取类属性的类型。
用法示例:
class MyClass {
public int $myProperty;
private string $anotherProperty;
}
$reflection = new ReflectionClass('MyClass');
$property = $reflection->getProperty('myProperty');
$type = $property->getType();
echo $type->getName(); // 输出:int
$property = $reflection->getProperty('anotherProperty');
$type = $property->getType();
echo $type->getName(); // 输出:string
解释说明:
注意事项: