Re: Re: Attributes and constructor property promotion
| From: | Benjamin Eberlei | Date: | Mon, 28 Sep 2020 13:08:30 +0000 |
| Subject: | Re: Re: Attributes and constructor property promotion | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111946@lists.php.net to get a copy of this message | ||
On Mon, Sep 28, 2020 at 2:25 PM Benjamin Morel <benjamin.morel@gmail.com>
wrote:
> On Mon, 28 Sep 2020 at 13:56, Benjamin Eberlei <kontakt@beberlei.de>
> wrote:
>
>
>> imho, we should pick the 80% use-case and advise to desugar the code if
>> other behavior is desired. For me the 80% case is that the attribute only
>> applies to the property, not to the parameter.
>
>
> +1 for the desugaring advice in this case, however as a matter of
> consistency I'd rather have it either apply to both the property and the
> parameter, or just throw an exception if used on promoted properties,
> whatever the 80% use-case is (source?)
>
We should assume that there are very few attributes that make sense to
apply to *both* a property and an argument. I can't find any good example
where this makes sense.
Library developers shouldn't be forced to allow target argument only that
it works in the ctor promotion case.
I assume the 80% case is properties, because attributes did not have
docblock annotations yet, that means this use-case isn't even possible at
the moment. Yet annotations on properties are widespread (Doctrine ORM,
symfony validator, ...).
> Kind regards,
> — Benjamin
>