Re: [RFC] Readonly Property Defaults
| From: | Nick Sdot | Date: | Mon, 13 Jul 2026 17:52:44 +0000 |
| Subject: | Re: [RFC] Readonly Property Defaults | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131896@lists.php.net to get a copy of this message | ||
Hey Tim,
On 14.07.26 00:07, Tim Düsterhus wrote:
Hi On 2026-07-09 21:18, Nick Sdot wrote:Not exactly sure what you would like me to spell me out. It's indeed different things. I made a tiny addition to the non-goals. Let me know if that's enough or if you had something else in mind.That probably depends a little on the definition of “prevent”. Technically you could implementThere is two options here: - The non-hooked unserialization path must also error out when trying to unserialize into a readonly property with a default value. - __unserialize() must be able to unserialize into a readonly property with a default value, similarly to __clone(). But the current situation of “__unserialize() is less powerful than the standard unserialization” is not acceptable, because it prevents introducingIt would not really have prevented using__unserialize()on a class with a readonly property with default values.__unserialize()on a class with a readonly property with default values.__unserialize(), sure. But you would be unable to unserialize into some of properties, which the native unserializer would be able to.But fair, I don't have a strong opinion here. Given that clone-with also allows modification of already initialised readonly properties your proposed option #2 is sound.Yes, I agree. clone-with already allows for the creation of object with a different value than the default, so allowing this for__unserialize()doesn't provide any new weird capabilities that result in inconsistencies. ------ As for the RFC, I have one more thing you could clarify: When using constructor property promotion, the default value will remain the default value of the parameter only and not suddenly also become the default of a property. It's a bit orthogonal to this RFC, and I find it reasonably obvious. But spelling it out to refresh everyone’s mind is probably a good thing nevertheless.
Other than that, I don't have any further comments on the RFC and in particular I don't see any more issues this would cause. Nevertheless, I'm probably team “Abstain” when it goes to vote :-) Best regards Tim Düsterhus-- Cheers Nick