Re: [RFC] Lazy Objects

From: Date: Thu, 25 Jul 2024 14:46:52 +0000
Subject: Re: [RFC] Lazy Objects
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

On 7/24/24 17:23, Nicolas Grekas wrote:
Cloning has kept us busy in the last days and after many brainstorming sessions, we've decided to follow your initial proposal : make the clone operator trigger the initialization of the original object before cloning it.
Thank you. That cloning behavior certainly is much easier to reason about.
I invite everybody to give the RFC a new read.
I'm seeing there are some more changes and not just to the cloning section. I've went through the entire RFC once again and here are my (hopefully final) five remarks. They are only about textual clarification of some behaviors, I don't have any further semantic concerns. 1. __destruct() is still called __destructor() in some places. 2. In the "Initialization Triggers" section, it says
The following special cases do not trigger initialization of a lazy object: Cloning, unless __clone() is implemented and accesses a property. This is no longer true with the latest changes.
3. In the "Proxy objects" initialization section, it says:
The value of properties used with ReflectionProperty::skipLazyInitialization() or setRawValueWithoutLazyInitialization() is discarded. I assume that the destructors of the values will be called if the reference count drops to zero? Then perhaps add "as if unset() was called" or "as if null was assigned to them" to make it clear that this is a regular reassignment and not some lazy object speciality.
4. In the "Proxy objects" initialization section, it says:
get_class() or the ::class constant evaluate to the class name of the proxy, regardless of the actual instance. This feels misplaced, because my understanding it that it is not something about the initialization, but rather proxy objects in general? Perhaps this is best moved to the "Real instance implementation" section in the Notes. It should also mention the behavior of the instanceof operator and also type declarations.
Perhaps some phrasing like the following is best: "The externally visible type of a lazy proxy is the type of the proxy object, even if the real object is of a parent type. This includes the get_class() function, the ::class constant, the instanceof operator and type checking in parameter, return and property types." 5. In the explanation of "ReflectionClass::markLazyObjectAsInitialized()", it says:
Its behavior is the same as described for Ghost Objects in the Initialization Sequence section, except that the initializer is not called.
This means that calling markLazyObjectAsInitialized() on a lazy proxy turns it into a regular object of the proxy class, as if newInstanceWithoutConstructor() was used, right? Best regards Tim Düsterhus

Thread (95 messages)

« previous php.internals (#124587) next »