Re: Validating #[\Attribute] targets

From: Date: Fri, 25 Jul 2025 16:42:38 +0000
Subject: Re: Validating #[\Attribute] targets
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-128230@lists.php.net to get a copy of this message
On Fri, Jul 25, 2025, at 11:33 AM, 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 I just checked AttributeUtils, and I don't *think* this will cause an issue. I do support interfaces and opt-in inheritance, but I don't believe it actually tags an interface with #[Attribute] anywhere. --Larry Garfield

« previous php.internals (#128230) next »