php / php/php-src

Add additional methods for reflections that have attributes

Open
#8,489 16 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: reflection Feature Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing getAttributes implementations for attributable reflections and the related ReflectionAttribute tests. Use ReflectionFunctionAbstract::getNumberOfParameters as the referenced precedent, then verify matching, flags, duplicate handling, and return values for the proposed methods across all attributable reflection types.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.