I just notice a flaw in my thinking. On Tue, 30 May 2023 at 02:48, Andreas Hennings <andr...@dqxtech.net> wrote: > > Note that for methods, we typically need to know the method reflector > _and_ the class reflector, because the method could be defined in a > base class.
This is true when doing a discovery using attributes. However, PHP does not know the original class when we call (new ReflectionClass('C'))->getMethod('f')->getAttributes(). So it cannot pass the original class into the attribute constructor. Currently, only the userland code that does the discovery knows the original class. We would need a type of method reflector that keeps track of the original class. This could well be its own separate RFC. Once this is done, we no longer need to pass the class as a separate argument. So to keep this RFC independent, we should only pass the reflector object where ->getAttributes()[*]->newInstance() was called on. Then if in a separate RFC we keep track of the original class in ReflectionMethod, the same information will be available when the method reflector is injected into an attributes. This also means that the ReflectionAttribute object needs to keep a reference of the original reflector. And if it does that, we can as well provide a method to return it. assert((new ReflectionClass('C'))->getAttributes()[0]->getReflector()->getName() === 'C'); -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php