(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
for fornecido.
O padrão é 0, que retornará apenas os resultados para atributos que
são da classe name.
A única outra opção disponível é usar ReflectionAttribute::IS_INSTANCEOF,
que usará instanceof para filtragem.
Array of attributes, as ReflectionAttribute objects.
| Versão | Descrição |
|---|---|
| 8.5.0 | This method was introduced. |
Exemplo #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));
?>O exemplo acima produzirá:
Array
(
[0] => Fruit
[1] => Red
)