Re: [RFC] [Discussion] Add ReflectionAttribute::getCurrent()
| From: | Daniel Scherzer | Date: | Wed, 06 May 2026 21:32:43 +0000 |
| Subject: | Re: [RFC] [Discussion] Add ReflectionAttribute::getCurrent() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130788@lists.php.net to get a copy of this message | ||
On Mon, May 4, 2026 at 2:13 PM Derick Rethans <derick@php.net> wrote:
> On 4 May 2026 21:24:39 BST, Daniel Scherzer <daniel.e.scherzer@gmail.com>
> wrote:
> >Hi internals,
> >
> >I'd like to start the discussion for a new RFC about adding a new method,
> >ReflectionAttribute::getCurrent(), to access the current reflection target
> >of an attribute.
> >
> >* RFC:
> >https://wiki.php.net/rfc/reflectionattribute-getcurrent
>
>
> "a new static method, ReflectionAttribute::getCurrent(), that, when called
> from an attribute constructor, returns a reflection object corresponding to
> what the attribute was applied to."
>
> This sounds like an arbitrary new rule for just this functionality. I
> don't think we should have special rules for a single static method call.
>
> I believe it's useful to have something like this, but I'm not in favour
> of this approach.
>
> Would it not be possible for this to be a normal (dynamic) method on the
> ReflectionAttrbute object?
>
> cheers
> Derick
In order to reduce the scope of the weird new method, I have updated the
RFC to split it up:
* ReflectionAttribute::getCurrent(), when called from an attribute
constructor, returns a *ReflectionAttribute* matching the usage (replacing
the currently-possible hacking with backtraces)
* ReflectionAttribute::getReflectionTarget() is a normal (dynamic) method
returning the ReflectionAttributeTarget
These are expected to be used together in the constructors of attributes,
e.g.
ReflectionAttribute::getCurrent()->getReflectionTarget(), but the
normal getReflectionTarget() method is also useful and usable elsewhere.
-Daniel