Am 06.08.2024, 11:01:54 schrieb Côme Chilliet <c...@chilliet.eu>: > Le mardi 4 juin 2024, 14:28:53 UTC+2 Nicolas Grekas a écrit : > > Dear all, > > > Arnaud and I are pleased to share with you the RFC we've been shaping for > > over a year to add native support for lazy objects to PHP. > > > Please find all the details here: > > https://wiki.php.net/rfc/lazy-objects > > > We look forward to your thoughts and feedback. > > > Cheers, > > Nicolas and Arnaud > > > > Hello, > > I’m a bit late to the party, but after reading the RFC I still do not > understand the difference between Ghost and Proxy. > I do understand the technical internal difference, I think, of 1 vs 2 > objects, and the API differences of passing a constructor vs a factory > function. > But I do not understand the difference from the caller point of view, how > would I choose when to use one or the other depending on my usecase? > > What does Proxy allows that Ghost do not? >
the primary use-cases for a proxy is when the class has a complex factory method and you want to make the class lazy on top. From a pattern POV, you can think of the proxy a decorator, it calls the complex factory in the initiailizer and then delegates all calls to it from there on. Taking Doctrine ORM as an example: $reflectionClass = new ReflectionClass(EntityManager::class); $entityManager = $reflectionClass->newLazyProxy(function (EntityManager $proxy) { return EntityManager::create($options); }); This is not possible with a Ghost, because that does not delegate, it "becomes the original class/object". > > Or do Proxy only make sense when returning a parent class from the factory > method? > > Côme >