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