Re: [RFC] Lazy Objects

From: Date: Sun, 30 Jun 2024 13:28:32 +0000
Subject: Re: [RFC] Lazy Objects
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

On 6/30/24 15:08, Tim Düsterhus wrote:
I've read the updated RFC and it's still not clear to me that returning an arbitrary “actual instance” object is sound. Especially when private properties - which for all intents and purposes are not visible outside of the class - are involved. Consider the following:
I initially wanted to include any new questions in a completely separate thread to keep stuff organized, but I realized that the cloning behavior is very closely related to what I already remarked above: The cloning behavior appears to be unsound to me. Consider the following:
    class A {
       public function __construct(
         public string $property,
       ) {}
    }
    class B extends A {
       public function foo() { }
    }
    function only_b(B $b) { $b->foo(); }
    $r = new ReflectionClass(B::class);
    $b = $r->newLazyProxy(function ($obj) {
      return new A('value');
    });
    $b->property = 'init_please';
    $notActuallyB = clone $b;
    only_b($b); // legal
    only_b($notActuallyB); // illegal
I'm cloning what I believe to be an instance of B, but get back an A. Best regards Tim Düsterhus

Thread (95 messages)

« previous php.internals (#124092) next »