Skip to content

Add additional methods for reflections that have attributes #8489

Open
@ollieread

Description

@ollieread

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions