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

Reply via email to