A PHP internals RFC discussion proposes adding ReflectionAttribute::getCurrent(), a static method callable from within an attribute constructor that returns the ReflectionAttribute instance corresponding to the current attribute usage. The core challenge is that inside an attribute constructor there is no direct access to the ReflectionAttribute instance without backtrace hacking. The RFC author Daniel Scherzer explains why alternative approaches — such as engine-level parameter injection or dynamic methods — would break backwards compatibility or create confusion for library authors. After feedback from Derick Rethans and others, the RFC was updated to split the feature into two methods: a static getCurrent() returning the ReflectionAttribute, and a normal dynamic getReflectionTarget() returning the reflection target, intended to be chained as ReflectionAttribute::getCurrent()->getReflectionTarget().

40m read timeFrom externals.io
Post cover image
117 Impressions