Closed
Description
I have created new issue to make it less doctrine specific.
Here is demonstration of different lazy proxies (modified proxy-manager examples)
use ProxyManager\Factory\LazyLoadingGhostFactory;
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
class Foo
{
public function compare(self $foo)
{
var_dump($foo === $this);
}
}
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(Foo::class, function (&$wrappedObject) {
$wrappedObject = new Foo();
return true;
});
$proxy->compare($proxy); // bool(false)
$proxy = (new LazyLoadingGhostFactory())->createProxy(Foo::class, fn() => true);
$proxy->compare($proxy); // bool(true)
First approach is used by Symfony. As you can see, it breaks identity and is more complicated to use. I suggest to use second method, which doesn't break identities. Would solve #35216 and issues related to it.
cc @stof