On Mon, Jul 5, 2021 at 1:56 PM Patrick ALLAERT <patrickalla...@php.net>
wrote:

> Le jeu. 1 juil. 2021 à 12:23, Nikita Popov <nikita....@gmail.com> a
> écrit :
>
>> Hi internals,
>>
>> I have opened voting on https://wiki.php.net/rfc/readonly_properties_v2.
>> The vote closes 2021-07-15.
>>
>> See https://externals.io/message/114729 for the discussion thread on this
>> proposal. I think a decent tl;dr is that readonly properties as proposed
>> do
>> not play well with clone-based withers, so some people believe we should
>> either improve cloning first, or introduce asymmetric property visibility
>> instead, which does not suffer from this issue.
>>
>> Regards,
>> Nikita
>>
>
> With the proposed implementation  the following class:
>
> class A {
>     public readonly string $name;
>
>     public function __construct(string $name) {
>         $this->setName($name);
>     }
>
>     public function setName(string $name) {
>         $this->name = $name;
>     }
>
>     public function setName2(string $name) {
>         $this->setName($name);
>     }
>
>     public function setName3(string $name) {
>         $this->name = $name;
>     }
> }
>
> Would behave like this:
>
> $a = new A("Initial name");
> echo $a->name, "\n"; // echoes Initial name
>
> $a->setName("New name"); // Allowed ?
> echo $a->name, "\n"; // echoes New name
>
> $a->setName2("Yet another name"); // Allowed ?
> echo $a->name, "\n"; // echoes Yet another name
>
> $a->setName3("Yet another name"); // Not allowed, although identical to
> setName()?
>
> [...]
>
> Is the above behaviour an implementation bug or does the RFC implies that?
>

This is indeed an implementation bug. Thanks for catching it! The issue
here is that the property write gets cached and bypasses the readonly
check, which of course shouldn't be happening.

Regards,
Nikita

Reply via email to