ReflectionParameter::getAttributes
Получает атрибуты
&reftitle.description;
public arrayReflectionParameter::getAttributes
stringnullname&null;
intflags0
Метод возвращает все атрибуты, которые объявили в параметре, в виде массива ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Массив атрибутов в виде объекта ReflectionAttribute.
&reftitle.examples;
Простой пример
getParameters()[0];
$attributes = $parameter->getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
[1] => Red
)
]]>
Фильтрация результатов по названию класса
getParameters()[0];
$attributes = $parameter->getAttributes('Fruit');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Fruit
)
]]>
Фильтрация результатов по названию класса, с наследованием
getParameters()[0];
$attributes = $parameter->getAttributes('Color', ReflectionAttribute::IS_INSTANCEOF);
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Red
)
]]>
&reftitle.seealso;
ReflectionClass::getAttributes
ReflectionClassConstant::getAttributes
ReflectionFunctionAbstract::getAttributes
ReflectionProperty::getAttributes