(No version information available, might only be in Git)
ReflectionConstant::getAttributes — Gets Attributes
Returns all attributes declared on this global constant as an array of ReflectionAttribute.
nameflagsname,则用于确定如何过滤结果的 flag。
默认值为 0,这将导致返回的结果只属于类 name 的属性。
唯一可用的其他选项是使用 ReflectionAttribute::IS_INSTANCEOF,它将改为使用 instanceof 进行过滤。
Array of attributes, as ReflectionAttribute objects.
| 版本 | 说明 |
|---|---|
| 8.5.0 | This method was introduced. |
示例 #1 Basic usage
<?php
#[Attribute]
class Fruit {
}
#[Attribute]
class Red {
}
#[Fruit]
#[Red]
const APPLE = 'apple';
$constant = new ReflectionConstant('APPLE');
$attributes = $constant->getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>以上示例会输出:
Array
(
[0] => Fruit
[1] => Red
)