ReflectionFunctionAbstract::getAttributes
Renvoie les attributs
&reftitle.description;
public arrayReflectionFunctionAbstract::getAttributes
stringnullname&null;
intflags0
Renvoie tous les attributs déclarés sur cette fonction ou méthode 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'objet ReflectionAttribute.
&reftitle.examples;
Utilisation basique avec une méthode de classe
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Utilisation basique avec une fonction
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
ReflectionClassConstant::getAttributes
ReflectionParameter::getAttributes
ReflectionProperty::getAttributes