Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124583 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 1C1821A00B7 for ; Wed, 24 Jul 2024 21:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721855024; bh=TNSjxWoZONwb3/IZv0l3+BPEvJ3fIJOWZn/AQgPT1R8=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=NRD0KfML0w4/MaQO8ZkBoL5H/zxQfrpJWcbmNUi8dHwXk64gGWTQcq/zUnZWcVO4m s3J6FaykLvr3lqUMj05b4US71e9YBpC8NkLSbSfoDpriCrB3QCSUzynBmnL+zqI74Y k4WpNFlnmTs+D0pdBqMwifKAd1vDM79Ocpe0U7M2aDOa4utWeUY5txxHCj0lDMAHlu eK9MIIBPTdf053pOnzVjHIetBgwyRgbzCKRwEEie6acPJkEcYCRfF/Zxyhyy4kUKzq CkvtlAO/bH5AYGorIS/M1LsFnstzMjG+e00jzm2GG+lwHrwMQIquKCQvSyfJ3c1Gjl lap6k1coYd9vQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2C12B18005B for ; Wed, 24 Jul 2024 21:03:43 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 ; Wed, 24 Jul 2024 21:03:42 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 834D411400AE; Wed, 24 Jul 2024 17:02:04 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute3.internal (MEProxy); Wed, 24 Jul 2024 17:02:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1721854924; x= 1721941324; bh=PgtY1dxwaf0S8rHwRLYADX1HkYIOay2xeLAbKBgd5Js=; b=A nmGTE0gQysSUg530Wwf9SVug2u1wMXPJYnZyg2ZRUhI7uF0SFYn6katUt0JIuBOt tiZdxbZRun7qOSbXSMQBp8C5ImfWEMF4WdNADzFWL0XinMCka5fO6ez8AtML7i/Y wQpyK55ob16eZfXC03EH4qzqICxNWHrX6SWrqCaaf/o7SVIpTNA2gU1/tVRdwXMz I7o+gXl3zkGz7skb1I2blBIKIEQ57M+wHjolPAma6qY93mlYTNA19TFx7jrvnlvh Oc3kZBg+nuCm8PxTzoXbWfuDrbttBQJldbwnriY0uUbyOOZnMl7L8TBuWElTWI4o 5KIjmBqIGQVoXbBjr0jeQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1721854924; x=1721941324; bh=PgtY1dxwaf0S8rHwRLYADX1HkYIO ay2xeLAbKBgd5Js=; b=oIxpTn7IR328vp20ydBe0CrCKnqGs3i3khDBVbAZ2vzU B2Qbp2XMD/filw5MiremCMyGgrWtItF39plemBqyOEKiSrWTNTpjwaQ3k2GVNMX3 qZE9/pweCGfWMbPn7zdYRp4/LP+EZNTlgziWENVRXaIaXMF68PrsLVh2WzDo/6X1 ScVwPUOSFZTHD/uie+eOZnHa8qm08y7I6qxASXU82L6Y9hXcSieZzK/ycXJPkO2m LwaUQQMvCMq5u0tEl4eUVuNNYbc3OYNuzpHvgj8nWIOw0auuQycRkXcVUDF3Xk+d 8eR/M8JBnCGWU2UlG44C3w+xuL+0w+jbK1rR/C2E9Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddriedugdduheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsegrtderreerreejnecuhfhrohhmpedftfho sgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtghouggvsheqnecuggftrf grthhtvghrnhepvdehkeetleevteefveegkefgffdvuefhleevhedvteeigfegtdefjeeh tefghfeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 02D0015A0092; Wed, 24 Jul 2024 17:02:03 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-582-g5a02f8850-fm-20240719.002-g5a02f885 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Message-ID: <4703efb9-75c2-4088-b660-f43a82aa7879@app.fastmail.com> In-Reply-To: References: <1118bbcd-a7b4-47bf-bf35-1a36ab4628e1@bastelstu.be> <45847b93-02bf-459f-bcd2-81ba35a12c24@bastelstu.be> <46bd4098-2936-4e46-98e9-fe55118325c2@bastelstu.be> <61ab36bc-b045-452a-84e0-87367d4c680e@bastelstu.be> <07e065f2-8f64-4bad-9a98-51f4eaf63ddb@app.fastmail.com> <2a0a4650-c2c5-4c6d-ad3a-25365b3391b2@bastelstu.be> <2fd6d80d-a55c-4aad-aeee-6d07d4b930a1@app.fastmail.com> <72131a21-1349-47fe-9267-ebad44575995@app.fastmail.com> Date: Wed, 24 Jul 2024 23:01:43 +0200 To: "Nicolas Grekas" Cc: "php internals" Subject: Re: [PHP-DEV] [RFC] Lazy Objects Content-Type: multipart/alternative; boundary=d3f67098e4284a52994842800a244cb5 From: rob@bottled.codes ("Rob Landers") --d3f67098e4284a52994842800a244cb5 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jul 24, 2024, at 22:45, Nicolas Grekas wrote: >=20 >=20 > Le mer. 24 juil. 2024 =C3=A0 21:44, Rob Landers a = =C3=A9crit : >> __ >>=20 >>=20 >> On Wed, Jul 24, 2024, at 16:28, Nicolas Grekas wrote: >>>=20 >>> To Rob: proxying by interface can be implemented using regular code = generation so it's not a blocker. Symfony does it already, and will cont= inue to do it to cover the use case. >>=20 >> I'm not sure what you mean, as the RFC makes it look this should be c= ompletely legal, until you get to the end: >>=20 >> interface Fancy { >> function sayHi(): void; >> } >> class A implements Fancy { >> function sayHi(): void { echo "hi!"; } >> } >>=20 >> $container->register(proxyType: Fancy::class, factory: fn() =3D> new = A()); >>=20 >> // Now container only knows that it needs to return a FancyClass and = this is "legal looking": >>=20 >> $lazy =3D new ReflectionClass($proxyType)->newLazyProxy($factory); >> // same as >> $lazy =3D new ReflectionClass(Fancy::class)->newLazyProxy(fn() =3D> n= ew A()); >>=20 >> This ^ compiles, it's perfectly legal and makes 100% sense that I sho= uld be able to call $lazy->sayHi() and it calls A::sayHi(), which is wha= t you would expect. Instead, this is runtime error. >=20 > The reason why this doesn't work is that the RFC is about state proxie= s, which means properties are required to hook the lazy behavior. > The RFC forbids your snippet because the initializer must return a par= ent of Fancy::class, which A::class isn't. >=20 > Please have a closer read of the RFC, we tried to describe the reasoni= ng as much as possible and this is covered. >=20 > Nicolas =20 >=20 My point was that this can=E2=80=99t be used for any DI container on the= planet (unless you parse the code and statically figure out what concre= te type is returned =E2=80=94 hope it is only one type =E2=80=94 and wil= l only work for the simplest of cases). There is nothing here that can b= e used for DI unless people are injecting concrete types and not using i= nheritance, which goes against the =E2=80=9Ccode to the interface=E2=80=9D= rule we=E2=80=99ve been using for the last 20-40 years=E2=80=A6 =E2=80=94 Rob --d3f67098e4284a52994842800a244cb5 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable

= On Wed, Jul 24, 2024, at 22:45, Nicolas Grekas wrote:


Le mer. 24 juil. 2024 =C3=A0 21:44, Rob Landers <rob@= bottled.codes> a =C3=A9crit :



On Wed, Jul 24, 2024, at 16:28, Nic= olas Grekas wrote:

To= Rob: proxying by interface can be implemented using regular code genera= tion so it's not a blocker. Symfony does it already, and will continue t= o do it to cover the use case.
I'm not sure what you mean, as the RFC makes it look this s= hould be completely legal, until you get to the end:

<= /div>
interface Fancy {
  function sayHi(): void;=
}
class A implements Fancy {
=   function sayHi(): void { echo "hi!"; }
}
<= div>
$container->register(proxyType: Fancy::class, fact= ory: fn() =3D> new A());

// Now containe= r only knows that it needs to return a FancyClass and this is "legal loo= king":

$lazy =3D new ReflectionClass($proxy= Type)->newLazyProxy($factory);
// same as
$lazy =3D new ReflectionClass(Fancy::class)->newLazyProxy(fn() =3D&g= t; new A());

This ^ compiles, it's perfectl= y legal and makes 100% sense that I should be able to call $lazy->say= Hi() and it calls A::sayHi(), which is what you would expect. Instead, t= his is runtime error.

The reason why this doesn't work is t= hat the RFC is about state proxies, which means properties are required = to hook the lazy behavior.
The RFC forbids yo= ur snippet because the initializer must return a parent of Fancy::class,= which A::class isn't.

Please have a closer read of the RFC, we tried to describe the rea= soning as much as possible and this is covered.

Nicolas  


My point was that= this can=E2=80=99t be used for any DI container on the planet (unless y= ou parse the code and statically figure out what concrete type is return= ed =E2=80=94 hope it is only one type =E2=80=94 and will only work for t= he simplest of cases). There is nothing here that can be used for DI unl= ess people are injecting concrete types and not using inheritance, which= goes against the =E2=80=9Ccode to the interface=E2=80=9D rule we=E2=80=99= ve been using for the last 20-40 years=E2=80=A6

=
=E2=80=94 Rob
--d3f67098e4284a52994842800a244cb5--