Re: [RFC] Readonly Property Defaults
| From: | Larry Garfield | Date: | Fri, 10 Jul 2026 23:02:19 +0000 |
| Subject: | Re: [RFC] Readonly Property Defaults | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131862@lists.php.net to get a copy of this message | ||
On Sat, Jul 4, 2026, at 5:03 AM, Nick Sdot wrote:
> Hey Internals,
>
> I would like to present a tiny, five-line-removal RFC allowing default
> values on readonly properties.
>
> Allowing default values on readonly class properties enables creating a
> strict contract for implementation property values that will not change
> at runtime -- as in, constant-like behaviour with contract. I would love
> doing that.
>
> Please find the RFC text here:
> https://wiki.php.net/rfc/readonly_property_defaults
I had been planning to say "meh, doesn't seem like it would hurt anything," but as
Tim pointed out with unserialize, it potentially could hurt something. That makes me skeptical.
I also want to call out, as the RFC notes, that this is already a solved problem with private(set).
It's not quite the same as readonly, but for most practical purposes it's close enough and
already addresses the use case this RFC.
--Larry Garfield