Re: [RFC] Readonly property hooks
| From: | Nicolas Grekas | Date: | Wed, 09 Jul 2025 06:30:31 +0000 |
| Subject: | Re: [RFC] Readonly property hooks | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127962@lists.php.net to get a copy of this message | ||
Hi Tim,
Le mar. 1 juil. 2025 à 16:29, Tim Düsterhus <tim@bastelstu.be> a écrit :
> 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.
>
> 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.
Here are two situations that are perfectly valid use cases for the example:
- event-sourced / versioned entities in the DB, where the state of an
object cannot change in the backend
- lazy-parsed network payloads, where one parses only part of some JSONs on
demand (mongodb and symfony/json-streamer do such things already)
Nicolas