ReflectionParameter::getAttributes
Pobiera atrybuty
&reftitle.description;
public arrayReflectionParameter::getAttributes
stringnullname&null;
intflags0
Zwraca wszystkie atrybuty zadeklarowane dla obecnego parametru jako tablicę obiektów ReflectionAttribute.
&reftitle.parameters;
&reflection.getattributes.param.name;
&reflection.getattributes.param.flags;
&reftitle.returnvalues;
Tablica obiektów ReflectionAttribute.
&reftitle.examples;
Podstawowe użycie
getParameters()[0];
$attributes = $parameter->getAttributes();
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Owoc
[1] => Czerwony
)
]]>
Filtrowanie wyników po nazwie klasy
getParameters()[0];
$attributes = $parameter->getAttributes('Owoc');
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Owoc
)
]]>
Filtrowanie wyników po nazwie klasy, z uwzględnieniem dziedziczenia
getParameters()[0];
$attributes = $parameter->getAttributes('Kolor', ReflectionAttribute::IS_INSTANCEOF);
print_r(array_map(fn($attribute) => $attribute->getName(), $attributes));
?>
]]>
&example.outputs;
Czerwony
)
]]>
&reftitle.seealso;
ReflectionClass::getAttributes
ReflectionClassConstant::getAttributes
ReflectionFunctionAbstract::getAttributes
ReflectionProperty::getAttributes