ReflectionClass::getAttributes
Récupère les attributs d'une classe
&reftitle.description;
public arrayReflectionClass::getAttributes
stringnullname&null;
intflags0
Retourne tous les attributs déclarés sur cette classe sous la forme d'un tableau de ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Un tableau d'attributs, sous la forme d'objets de type ReflectionAttribute.
&reftitle.examples;
Utilisation basique de ReflectionClass::getAttributes
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Rouge
)
]]>
Filtrer les résultats par un nom de classe
getAttributes('Fruit');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
)
]]>
Filtrer les résultats par nom de classe, avec héritage
getAttributes(Couleur::class, ReflectionAttribute::IS_INSTANCEOF);
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Rouge
)
]]>
&reftitle.seealso;
ReflectionClassConstant::getAttributes
ReflectionFunctionAbstract::getAttributes
ReflectionParameter::getAttributes
ReflectionProperty::getAttributes