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()? I find the word "scope" very confusing to understand in: > A readonly property can only be initialized once, and only from the scope > where it has been declared. Any other assignment or modification of the > property will result in an Error exception. Is the above behaviour an implementation bug or does the RFC implies that? Regards, Patrick