(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 が指定されていた場合に、
結果をどうフィルタするかを決めるフラグ。
デフォルトは 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
)