ReflectionClassConstant::getAttributes
Vérifie les attributs
&reftitle.description;
public arrayReflectionClassConstant::getAttributes
stringnullname&null;
intflags0
Vérifie tous les attributs déclarés sur cette constante de classe sous forme d'un tableau de ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Un tableau d'attributs, sous forme d'objets ReflectionAttribute.
&reftitle.examples;
Utilisation simple
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Résultats filtrés par nom de classe
getAttributes('Fruit');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
)
]]>
Résultats filtrés par nom de classe, avec héritage
getAttributes('Color', ReflectionAttribute::IS_INSTANCEOF);
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Red
)
]]>
&reftitle.seealso;
ReflectionClass::getAttributes
ReflectionFunctionAbstract::getAttributes
ReflectionParameter::getAttributes
ReflectionProperty::getAttributes