On Mon, Sep 28, 2020 at 5:36 AM Nikita Popov <nikita....@gmail.com> wrote:
> When the constructor property promotion landed, the question of how it > interacts with attributes on promoted properties did not get fully > resolved. See https://wiki.php.net/rfc/constructor_promotion#attributes > for > what the issue is. > > The behavior that landed was to apply the attribute is applied to both the > parameter and the property. However, this was with the understanding that > we may have to adjust the behavior later, in particular depending on how > the whole "attribute target validation" turns out. The way it is now, using > a property-only attribute on a promoted parameter may result in spurious > validation errors. > > I wanted to bring up this topic now to make sure it's not forgotten... I > still don't really know what the best behavior here is. > > My opinion on constructor property promotion (CPP) is that it's something for small value object classes and should probably be regarded as code-smell on larger classes. At the same time, annotations belong with more complex objects and not so much with small "struct-like" classes. Given that position, I think we should err towards strictness in how attributes are applied to CPP declarations. That is, we should require them to be meaningfully applicable to both arguments and properties in order to be used in a CPP context. If that's a problem for the consumer, then they should avoid use of CPP. -Sara