Re: [RFC] Property Hook improvements
| From: | Claude Pache | Date: | Wed, 03 Jul 2024 12:28:04 +0000 |
| Subject: | Re: [RFC] Property Hook improvements | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-124190@lists.php.net to get a copy of this message | ||
> Le 3 juil. 2024 à 11:54, Claude Pache <claude.pache@gmail.com> a écrit :
>
>
> 2. As for readonly, I think that the invariant it is supposed to provide should be enforced as
> strictly as possible. It means that
readonly is only acceptable if
> there is no get hook.
Hi,
One more thing, why I think that we should be strict here. It is not just for preventing the user to
write *dumb* code, it is also for preventing them to write *creative* code, e.g.
```php
class doc {
public readonly int page {
get => $this->page + $this->offset;
}
private int $offset = 0;
public function __construct(int $page) {
$this->page = $page;
}
public function foo() {
// $this->offset may be adjusted here
}
}
```
—Claude