Re: [PHP-DEV] [RFC] Readonly Property Defaults

[email protected] (Tim Düsterhus) Thu, 09 Jul 2026 11:12:09 +0200
Newsgroups php.internals
Message-ID <[email protected]>
Hi

On 2026-07-04 12:03, Nick Sdot wrote:
> 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

Thank you, the proposal makes sense to me. I have just some requests for 
clarification:

1.

Can you add a “clone-with” example to the “Interaction with clone” 
section? I assume that “clone-with” will also just work for the same 
reasons, but it makes sense to spell it out.

2.

Can you spell out the unserialization behavior with an example. 
“Unserialisation continues to use the existing object hydration 
semantics and is not changed by this RFC” is not clear to me, because 
from my mental model unserialization first does a 
`newInstanceWithoutConstructor()` and then fills in the properties based 
on the serialized data. Thus a readonly field with a default value would 
already be initialized, which means that filling in the serialized data 
would fail, which I think is not a situation we have so far.

3.

In the “Interaction with asymmetric visibility” section, the example 
would be stronger with a `public(set)` instead of `private(set)`, 
because with `private(set)` the example would fail either way, since the 
global scope has no access to the property.

4.

Minor polishing remark in “Interaction with traits”: The opening PHP tag 
is missing in the example.

Best regards
Tim Düsterhus