Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124800 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id AE48A1A00B7 for ; Tue, 6 Aug 2024 09:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722936671; bh=HkU0Su7/i5xwh6FUl3RQuG8VAOGPY52jxupWs6f44jA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Q4QOu3JPmc00U8dWWJdzZio9LawtSsP31g6rhkWrkJP3fiOmEbfx1IWhm347DYT5f AJRR2f6cMwevArqbf6YipWUDVvZZ9QZZDwPxhxHp2Z+TRGoM4VtM+G/r92mwMk/RXo BgTfyH+4o20CTQbov4EFL0P4mYXbZCyAkFAUFj1B/eX+vdO6N7gk8lpJailXskIx/L 82Qqq71UPrJE2nIfZ2xNmJw4B+KNwy2M1Nnhxdt/+UpvmN7m/UNrkPDW/XTcmBRU9/ CvrrAzDECV2ahv7SIxSTkiMLjO5l52k8PY/phK1hSRxHdpd0uSM9cwhWUOhk7T2/e1 ACM0UmLdhO7tA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE7EA18006F for ; Tue, 6 Aug 2024 09:31:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Aug 2024 09:31:10 +0000 (UTC) Received: by mail-vs1-f46.google.com with SMTP id ada2fe7eead31-4929fa64542so136929137.3 for ; Tue, 06 Aug 2024 02:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20230601.gappssmtp.com; s=20230601; t=1722936568; x=1723541368; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0aMo7cupbB7rnFBSVCn1g2mg2RwCVcxl1M98+66t3js=; b=NdjLHxM2d5xaE118CAkC1/q1jpeJo0dImDhpkjZu8mkUYpFDEttgCqxO4FnKFCfBPP wuuHdcoiOour8q6XwZ4I6aNSSannMUFuPQ1TiZpgwVA9paSrfI671NsnnYk5Si13CS1B tCFfnb3o2rvYZb79YLtdQ+faXaK1Kvoia3bYyQPaKWsk8aQf+fjdqMDCZLEdmt1TX5L3 UIn7WLxGoBlK/ELKmPG+ZErtg10a0hrq3LxjIZITuoKUKJq8iLk+ijo7SnfXh+UKDT9O 5Biv1lbjUqhHV6CbYp0fWuUxnCwFWOxmhmkzcg/oYQ4A6oyqTtQs/9F2ov75M5/vuuv1 1muw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722936568; x=1723541368; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0aMo7cupbB7rnFBSVCn1g2mg2RwCVcxl1M98+66t3js=; b=rTXSmWt3+QGEWE3S2PEPvl/iZ/5zR+T4PidFvg/o8zKgkuz8StMtSakh3zhPUjrAIa V/vIl7D7ObVR7sfWWT+Xp6Jm5dXIYjN6MPhUD6o46163ZBZyuRpdVGiS8B7KRyw7HEpz mo0xNsQjWBslBlfheOkvP3jrADCZ7HzTgBAEu3AX4HTuQ+6OwzcdwoJuJa5GLBdqxhef 7nYsX9oyZm3cF5naZj3Ot2nfw1NfzS12NFmRU//Sgi/IeJEkyNGEvDgHiHFWreFQj8Gg p1TrrlgG4put/dTT/WlGdqn2DSh8hKsKNn+DiTenhl3ZPmtp1Aj+TDlJKJech9MU0Axe r6kw== X-Gm-Message-State: AOJu0Yx60rCieo0JgDvBFzHzkhG5Ei1Wc2s0n0HIb8vlC9oGJHWdNYxW XxyqvIN3yfsIsCjMSUiiiWtcF9xi4Qu7ZLcwJEmhvUSrjIZNpDRWPx4IpVpCDjCMCG9D8yjkMie rPFyzxpKzntUil+uoS3vXhrP1d4nJ9wdJM7waCD/ypjrb2f4E X-Google-Smtp-Source: AGHT+IEgprADIp5VYQqXpvK7/QLE5cOH7J5JMFvddSOov3B7Q9WqLH/5rj3jK/sym9PdHR1pR0+0IEskt2ODiLgAuTg= X-Received: by 2002:a05:6102:4409:b0:493:ea2c:6bb with SMTP id ada2fe7eead31-4945be19575mr15273501137.15.1722936568198; Tue, 06 Aug 2024 02:29:28 -0700 (PDT) Received: from 1064022179695 named unknown by gmailapi.google.com with HTTPREST; Tue, 6 Aug 2024 09:29:26 +0000 Received: from 1064022179695 named unknown by gmailapi.google.com with HTTPREST; Tue, 6 Aug 2024 11:29:24 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 (Mimestream 1.3.7) References: <4584782.LvFx2qVVIh@come-prox15amd> In-Reply-To: <4584782.LvFx2qVVIh@come-prox15amd> Date: Tue, 6 Aug 2024 09:29:26 +0000 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: =?UTF-8?Q?C=C3=B4me_Chilliet?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000001e5405061f006e84" From: kontakt@beberlei.de (=?UTF-8?Q?Benjamin_Au=C3=9Fenhofer?=) --0000000000001e5405061f006e84 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Am 06.08.2024, 11:01:54 schrieb C=C3=B4me Chilliet : > Le mardi 4 juin 2024, 14:28:53 UTC+2 Nicolas Grekas a =C3=A9crit : > > 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=E2=80=99m 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 =3D new ReflectionClass(EntityManager::class); $entityManager =3D $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 factor= y > method? > > C=C3=B4me > --0000000000001e5405061f006e84 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Am 06.08.2024, 11:01:54 schrieb C= =C3=B4me Chilliet <come@chilliet.eu<= /a>>:
=20
Le mardi 4 juin 2024, 14:28:53 UTC+2 Nicolas Grekas a =C3=A9crit :
<= blockquote type=3D"cite"> 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 PH= P.

Please find all the details here:
https://= wiki.php.net/rfc/lazy-objects

We look forward to your thoug= hts and feedback.

Cheers,
Nicolas and Arnaud


Hello,

I=E2=80=99m 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 us= ecase?

What does Proxy allows that Ghost do not?

the primary use-cases for a p= roxy is when the class has a complex factory method and you want to make th= e class lazy on top. From a pattern POV, you can think of the proxy a decor= ator, it calls the complex factory in the initiailizer and then delegates a= ll calls to it from there on.
<= br>
Taking Doctrine ORM as an e= xample:

$reflectionClass =3D new ReflectionClass(EntityMa= nager::class);
$entityManager = =3D $reflectionClass->newLazyProxy(function (EntityManager $proxy) {
=C2=A0 =C2=A0 return EntityManager= ::create($options);
});

This is not possible with a Ghost, because that does not delegat= e, it "becomes the original class/object".

Or do Proxy only make sense when returning a paren= t class from the factory method?

C=C3=B4me
--0000000000001e5405061f006e84--