On Fri, Jul 25, 2025, at 18:33, Daniel Scherzer wrote:
> Hi internals,
>
> The #[\Attribute] attribute is used to mark classes as being usable as attributes. It currently does not trigger any error if added to a trait, interface, enum, or abstract class. However, if any of those *were* used as an attribute, calling ReflectionAttribute::newInstance() would fail; if you are not going to call ReflectionAttribute::newInstance(), then you don't really need to mark the trait/interface/enum/abstract class as an attribute.
>
> I have proposed https://github.com/php/php-src/pull/19154 to add validation to the #[Attribute] attribute, and it was suggested that I post here on the mailing list in case there were any objections. So, are there?
>
> -Daniel
Since \Attribute itself is an attribute, I wouldn’t expect it to be validated until newInstance is called. In fact, if I remember correctly from the original discussion, this was done deliberately so it would be forward compatible. Further, by making it compile-time validated, I would be misled to think my own attributes would be validated at compile time (which I think is a better solution than hodgepodging our way there).
— Rob