-
Couldn't load subscription status.
- Fork 8k
Description
Description
All currently attributable reflections have a single method relating to attributes.
getAttributes(?string $name = null, int $flags = 0): array
Additional methods for dealing with attributes would be a nice improvement and would simplify common approaches. I'm proposing the following methods.
getAttribute
Get a single instance of ReflectionAttribute, following the same rules as getAttributes, minus the fact that $name is required.
getAttribute(string $name, int $flags = 0): ?ReflectionAttribute
If more than one attribute matches, an exception should be thrown.
hasAttribute
Functionally identical to getAttribute, except it will return true if one or more matches are found, otherwise it returns false.
hasAttribute(string $name, int $flags = 0): bool
getNumberOfAttributes
Again, follows the same rules as getAttributes, but will return the number found. This particular method is based on the ReflectionFunctionAbstract::getNumberOfParameters method.
getNumberOfAttributes(?string $name = null, int $flags = 0): int