The Daily Commit · Section Edition Front Page PHP AI Dev EN DE FR ES

The Php Times

RFC Watch — Ecosystem

[RFC] Readonly Property Defaults


Proposal to allow default values on readonly class properties, enabling strict contracts with constant-like behaviour that cannot change at runtime.

PHP INTERNALS ([RFC]/[VOTE]), July 9, 2026 curated by Heiko

The RFC introduces a minimal change to permit initialization of readonly properties without constructor assignment, strengthening type safety and reducing boilerplate in implementations.

Nick Sdot has proposed an RFC to allow default values for readonly class properties in PHP. The change is described as a minimal technical modification—removing just five lines of code—that enables constant-like behaviour with strict contracts without requiring constructor assignment.

During the review process, discussions with Tim Düsterhus focused on technical edge cases. Clarifications were added regarding the interaction with the "clone-with" feature and asymmetric visibility. Specifically, the RFC now clarifies that using public(set) visibility provides a more accurate example than private(set).

Significant attention was given to unserialization behavior. Because a readonly property with a default value is already initialized when __unserialize is called, assigning to it during object hydration will fail. This differs from the current behavior around readonly properties during unserialization.

Read the original source ↗

Rate this article: 0

Readers’ Forum

No contributions yet — open the debate.

← Ecosystem — Page B1

"All the Code That's Fit to Ship" · The Daily Commit · Screen edition · Imprint · Privacy Policy