Re: Allow hooks in `readonly` promoted properties
| From: | Larry Garfield | Date: | Mon, 02 Jun 2025 13:39:12 +0000 |
| Subject: | Re: Allow hooks in `readonly` promoted properties | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127531@lists.php.net to get a copy of this message | ||
On Mon, Jun 2, 2025, at 7:49 AM, Nick wrote:
> Dear Internals,
>
> I am sending my first message here. Thank you all for your hard work!
Greetings.
> I believe promoted properties should allowed for
readonly
> properties
> and in readonly classes. This would help us to avoid the
> unnecessary
> boilerplate like outlined above.
>
> That said, I would greatly appreciate if internals could explore to
> allow readonly for hooks in promoted properties in 8.5.--Cheers
> &
> thanks,Nick
This was discussed heavily in the design and discussion phase for hooks. The main problem is that
the expectations for readonly and the expectations for hooks don't always align. For example,
if a virtual property has a get-hook, can it be readonly? We cannot guarantee that the property
will always return the same value, but that is rather the expectation of readonly.
Given how large and complex the RFC was already, we collectively decided to punt on that question
until later. Ilija and I did tepidly propose loosening the restriction slightly:
https://wiki.php.net/rfc/readonly_hooks
Though we've not gotten back to it as we've both been busy and there hasn't been a
ton of calls for it, and it likely still needs to be tweaked some.
Another possibility might be to have the readonly marker on a class just skip applying to virtual
properties. So you cannot specify it explicitly, but a class-level readonly no longer causes a
conflict. I don't know how viable that is off hand.
--Larry Garfield