ReflectionFunctionAbstract::getAttributes
Obtém atributos
&reftitle.description;
public arrayReflectionFunctionAbstract::getAttributes
stringnullname&null;
intflags0
Retorna todos os atributos declarados nesta função ou método como um array de ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Array de atributos, como um objeto ReflectionAttribute.
&reftitle.examples;
Uso básico com um método de classe
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Uso básico com uma função
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Filtrando resultados por nome de classe
getAttributes('Fruit');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
)
]]>
Filtrando resultados por nome de classe, com herança
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