Re: [RFC] Readonly property hooks

From: Date: Tue, 08 Jul 2025 15:10:33 +0000
Subject: Re: [RFC] Readonly property hooks
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-127958@lists.php.net to get a copy of this message
On Tue, Jul 1, 2025, at 9:27 AM, Tim Düsterhus wrote: > Hi > > Am 2025-06-09 17:11, schrieb Larry Garfield: >> I also fleshed out the __get mention with an example that shows what >> you can already do today, and in fact could since 8.1 when readonly was >> introduced. The hard guarantee of idempotency has never actually been >> there. (This also speaks to Claude's concern.) > > I don't think this really resolves Claude's concern. While it is > certainly true that the guarantees do not currently hold, I don't > believe this is strong enough of a reason not to provide for stronger > guarantees in a *newly introduced feature*. The point of property hooks > is for me that “dynamic properties” are easier to reason about compared > to __get(). As a user when accessing a proper > readonly property, I > do not want to check if there is a property hook that might result in > non-readonly behavior. As an engine developer I want to be able to > optimize based on the readonly-ness of a property. Without such > > guarantees, the “readonly” keyword does not provide value to me. The only way to make the readonliness fully guaranteed would be to force a readonly property to be cached; (IE, the hook is only called at all if the property is uninitialized.) But there's no obvious way to make that clear in the code that it's what's happening. > I also believe the LazyProduct example to be broken, since lazy-loading > individual properties might result in an object that is internally > consistent if the database changes in-between. That's true with any lazy-loading scenario. The use of hooks doesn't change that at all. --Larry Garfield

« previous php.internals (#127958) next »