ReflectionFunctionAbstract::getAttributes
Получает атрибуты
&reftitle.description;
public arrayReflectionFunctionAbstract::getAttributes
stringnullname&null;
intflags0
Возвращает все атрибуты, объявленные для этой функции или метода, в виде массива ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Массив атрибутов в виде объекта ReflectionAttribute.
&reftitle.examples;
Простой пример с методом класса
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Простой пример с функцией
getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Фильтрация результатов по имени класса
getAttributes('Fruit');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
)
]]>
Фильтрация результатов по имени класса, с наследованием
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