Re: [RFC] Asymmetric Visibility, with readonly
| From: | Larry Garfield | Date: | Sun, 13 Nov 2022 21:57:20 +0000 |
| Subject: | Re: [RFC] Asymmetric Visibility, with readonly | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118997@lists.php.net to get a copy of this message | ||
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