> On Thu, Mar 26, 2020 at 2:30 PM Nikita Popov <nikita....@gmail.com> wrote:
>
> > Hi internals,
> >
> > I would like to submit the following RFC for your consideration:
> > https://wiki.php.net/rfc/constructor_promotion
> >
> > This is based on one off the suggestions made in
> > https://externals.io/message/109220, and some existing discussion on the
> > topic can be found in that thread.
> >
> > The primary motivation for this feature is to close the currently rather
> > wide gap between the use of ad-hoc array structures, and the use of
> > well-defined and type-safe value objects. The latter is what we want
> people
> > to use, but the former is, unfortunately, what is *easy* to use.
> >
>
> As it looks like the Attributes RFC is going to be accepted, we need to
> consider how it will interact with this proposal. I've added an extra
> section for this:
> https://wiki.php.net/rfc/constructor_promotion#attributes
>
> The problem is that attributes are allowed both on properties and on
> parameters. For promoted properties, what does the attribute apply to? My
> original suggestion was to make it apply to both the parameter and the
> generated property. However, Benjamin pointed out that an attribute on a
> promoted property is almost certainly intended to apply to the property
> only, especially because parameter attributes have not been supported
> historically (in phpdoc). Applying it to both the property and the
> parameter may cause issues for attributes that want to strictly validate
> where they are used.
>
> I think the best answer to this question may be to forbid the use of
> attributes on promoted properties entirely, because there is no unambiguous
> interpretation for them. I also think that using attributes pushes this
> "syntax sugar" to its limit, as you can easily end up with a 50 line
> constructor signature that way, at least if I'm going by some of the more
> involved uses of annotations...
>

This last proposal would kinda defeat constructor promotion and all the
reasons why it was introduced in the first place.

I would expect attributes to apply only to the properties on my side.

If people want different or duplicate attributes on parameters, then it's
normal to not be able to use constructor promotion.

My 2cts,
Nicolas

Reply via email to