On Wed, Apr 8, 2020 at 1:56 PM Nicolas Grekas <nicolas.grekas+...@gmail.com>
wrote:

>
> I would like to submit the following RFC for your consideration:
>> https://wiki.php.net/rfc/constructor_promotion
>>
>
> I love it :)
>
> Just one question:
> Shouldn't default values be copied on the signature? That would be
> expected for me.
> (and that would make the properties still initialized when child classes
> don't call the parent constructor for whatever reasons.)
>
> class Point {
>     public function __construct(
>         public float $x = 0.0,
>
> <==>
>
> class Point {
>     public float $x = 0.0;
>
>     public function __construct(
>         float $x = 0.0,
>
> Nicolas
>

Some reasons why the default value is not duplicated into the property are
discussed in https://wiki.php.net/rfc/constructor_promotion#desugaring.
It's primarily about forward-compatibility concerns.

But apart from that, I strongly believe that you should not, ever, specify
a default value on a property that is initialized in the constructor. You
can have a default, or you can have explicit initialization in the
constructor -- both together do not make sense.

Regards,
Nikita

Reply via email to