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 attribute constructors have no direct access to the ReflectionAttribute object, so the implementation uses C-level backtrace processing. The RFC author and community members debate design trade-offs: using a static 'magic' method vs. engine-level constructor injection vs. a dynamic method. The RFC was updated to split the feature into two methods: getCurrent() (static, context-sensitive) and getReflectionTarget() (normal dynamic method), intended to be chained as ReflectionAttribute::getCurrent()->getReflectionTarget().

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