On Sun, Nov 13, 2022, at 3:50 PM, Deleu wrote:
>>
>>
>> 2. `readonly` is a "write once" flag that may be combined with asymmetric
>> visibility.  If no set visibility is specified, `readoly` implies
>> `private(set)`, but a different set visibility may also be provided.
>>
>> These are both reasonable rules.  However, it creates a conflict.
>> Specifically, in the following cases:
>>
>> public public(set) readonly string $foo
>>
>> protected protected(set) readonly string $foo
>>
>
> What if the implicit rule for `readonly` is changed into `protected(set)`?
> Let's run with this for a minute.
>
> 1- It's not truly a CODE breaking change. Right now if you have a
> `protected readonly` property, you're either calling the parent constructor
> or you're never making use of the variable, otherwise you're getting a
> Fatal Error.

This is untrue.  You can declare a private property identically in a parent and 
child class, even readonly.  I'm doing this now in a project.  It works, but 
would be unnecessary if the parent's property were protected(set).

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to