Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124582 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 5FE151A00B7 for <internals@lists.php.net>; Wed, 24 Jul 2024 20:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721854054; bh=gLKTIlSHuMe31rNXrjN23BvAVdituUUtznseOVgqzCI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EE0Wx/IxkCH8uRdLVGji4aVQDEKhZZvShImzb81K9HvdxtuR/TXRK80gcSRRnUEYk hE05T5uEGzxwVc7RwbRMNE36dm53MWTql4Fcnp6uIudn4VxW8hstL9tKEdolsbiEMx x9Tmt6Cd/Mv/Qjuo52JlGbyc/8knWiaS641dI5oPaBkoGy1iHBMtRZbZ+kSET2Cek1 Ulca/uhulXQKeo2Be2THZHyuOnVOi5fnDO8H7PhgbdciE7vu7AFMerU1/+vaSMWhIt jKMRBZyezRxp80AzhBY8qNgtV2Bww3OQ5vQzvS9TPOJHg23EXer6L8BxF8a+XcfCiq yZT5Kti457s2A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A3EE818003E for <internals@lists.php.net>; Wed, 24 Jul 2024 20:47:33 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: <nicolas.grekas@gmail.com> Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 <internals@lists.php.net>; Wed, 24 Jul 2024 20:47:33 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-52efa9500e0so112123e87.3 for <internals@lists.php.net>; Wed, 24 Jul 2024 13:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721853957; x=1722458757; 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=ocrWqKhMD1VzUZB6Pz8yimSQaI6iBAz3RZlpohShRm4=; b=XgjUFsE4eRs0VQSY4/ou28r32mXrqXciXBa+OnvMpJPCHNbIfNL5hgLBnoPOFJP7L1 KiW+vle/lq/wQ2gopdbbuW0CJSpWi0bkxxmF28uTvM2M1iyq3vNsHILwTjNiZszD0u9U 8U3jf16s390ULvei7GirpO0hRSR2gMeIT3Fyl+EfbmD8cglFQj9+mbkkwLvkjFasTQEC mte40PLKBP1fkiQe9C11IrI2zGqo0J8TEMfS6QDk/hPc9LcNsYDRAt7rg85q8IG5xFZP l46DMXbYisGpWHc1wp5lxvDcPj4Hum7ifQ0igWeD3B1NHC8K6cgTlAmTBD/a6JKLprZp aPSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721853957; x=1722458757; 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=ocrWqKhMD1VzUZB6Pz8yimSQaI6iBAz3RZlpohShRm4=; b=CQ6SjvwLIZQ3vXHUFQOTDV+6ZinuDRV/0VISXOChi0FnY2UEynuVkyWngwVxqI02pc /noXdNEkjewX/m767KDX+u/YORqXvl43dCLFUBYy7dW3Ru9pIv1rJgPOtueCFJ/+QS8L z7NJvUlYR2I4ySjiYXbCLZYdqy5y3ZIr37ozAw+jez0m27MEGNzH2eyUylF/M2/xfSts 0nVfNUsLIHnMIXoGM6YtmvwKHeMdIaqlpQzf3CQh05P1ZitPJhZ0ccBgdTxvMDj0hV+4 KwpHus/3gyfZ6bj1kwDfNvkaf9rUYVAr8NhW91uhTnWUvNfDGHmj3C5TIdAZud8pUGcu 2xFA== X-Gm-Message-State: AOJu0YzV1VvGQhXu9FGDO69FqpnRERI0sXK5Ckv0PdhrBQ2zdelwN1SZ Tc+zuDwM4CyWTIlh3h5EZL3in6eB+hWqPJ9P+16s0uqlezLdoeHCCZdwmdzjg2MrNBsv9SeMr2K bWmfe6cwUog/I+CVAZ4131md/dk4yOQ== X-Google-Smtp-Source: AGHT+IEPobjYQb/ImmM38ygDW5mEna0+iSbCvN1tERBWlabX1PWTVBUbGcuBBSJ5eWbk5A+O67CFTrum1RxZ+f6SfHY= X-Received: by 2002:a05:6512:1252:b0:52c:df9d:7cbe with SMTP id 2adb3069b0e04-52fd3f6686cmr624614e87.39.1721853956700; Wed, 24 Jul 2024 13:45:56 -0700 (PDT) Precedence: bulk list-help: <mailto:internals+help@lists.php.net list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net> list-post: <mailto:internals@lists.php.net> List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <CAOWwgpmbq5VRrZQvUXDsKiNK4r6+bFA4VxnjQ_U=h8T9r0o3DA@mail.gmail.com> <ab83af79-0669-47dd-a3cb-ab72327ae174@bastelstu.be> <CAP1Jc13JWVg99AULgzrGXcoCWJtJZGz+nr_VoyUocw8n5n5sfQ@mail.gmail.com> <1118bbcd-a7b4-47bf-bf35-1a36ab4628e1@bastelstu.be> <CAP1Jc11vNiazMRL8Y-4NcJhsEkg6kgFNKLymTGfEPYRv114oTA@mail.gmail.com> <45847b93-02bf-459f-bcd2-81ba35a12c24@bastelstu.be> <CAOWwgpnt77-Sybzc3hcnFEui9t8wAv03NAov4xCK9ib_VRZ0JA@mail.gmail.com> <46bd4098-2936-4e46-98e9-fe55118325c2@bastelstu.be> <CAOWwgpkCy++W1C2t0PnkZ71S8vq1B734ZNPGw2-OHjmrwO3L4A@mail.gmail.com> <61ab36bc-b045-452a-84e0-87367d4c680e@bastelstu.be> <CAEPJduk6m1gdPOrsXYbsc+RLuHeEBav3pGwQO+PHs4UGGqtzhg@mail.gmail.com> <07e065f2-8f64-4bad-9a98-51f4eaf63ddb@app.fastmail.com> <CAOWwgpngQtg2NRW6M6RwgSH+OS1iipewHBmM5c36P2MxQGX78A@mail.gmail.com> <2a0a4650-c2c5-4c6d-ad3a-25365b3391b2@bastelstu.be> <CAOWwgpm9FLy_SNt7HLtJh5sxtfwjZMMN6pOKioDqsJc+GgD-sA@mail.gmail.com> <CAOWwgpnwoPH_rkJreh8v+X8WagzcCJ_puT1RWC0c717GMj5Onw@mail.gmail.com> <CAOWwgp=uwDebrx-=H8yP1Dgwf9ji=v_qagw9aAxbDJcPvCqKNw@mail.gmail.com> <b096b1d3-4414-4b53-a3b0-3a87c8dd7ff3@app.fastmail.com> <CAOWwgp=88jWSR-roWTrkkgwVgQvLQYbkTGSGAr6ASPs6s7s_4g@mail.gmail.com> <2fd6d80d-a55c-4aad-aeee-6d07d4b930a1@app.fastmail.com> <CAOWwgp=zu8y95EyEvjidNuiBOr8-ckek_xFmrcA_JifLy3U2Xg@mail.gmail.com> <72131a21-1349-47fe-9267-ebad44575995@app.fastmail.com> In-Reply-To: <72131a21-1349-47fe-9267-ebad44575995@app.fastmail.com> Date: Wed, 24 Jul 2024 22:45:44 +0200 Message-ID: <CAOWwgp=apEVtNTr-3_oT1ndTTCuKmkvhsctn7QNqWVKPuZuqVg@mail.gmail.com> Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: Rob Landers <rob@bottled.codes> Cc: php internals <internals@lists.php.net> Content-Type: multipart/alternative; boundary="00000000000071c4f9061e045da0" From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --00000000000071c4f9061e045da0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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, Nicolas Grekas wrote: > > > To Rob: proxying by interface can be implemented using regular code > generation so it's not a blocker. Symfony does it already, and will > continue to do it to cover the use case. > > > I'm not sure what you mean, as the RFC makes it look this should be > completely legal, until you get to the end: > > interface Fancy { > function sayHi(): void; > } > class A implements Fancy { > function sayHi(): void { echo "hi!"; } > } > > $container->register(proxyType: Fancy::class, factory: fn() =3D> new A())= ; > > // Now container only knows that it needs to return a FancyClass and this > is "legal looking": > > $lazy =3D new ReflectionClass($proxyType)->newLazyProxy($factory); > // same as > $lazy =3D new ReflectionClass(Fancy::class)->newLazyProxy(fn() =3D> new A= ()); > > This ^ compiles, it's perfectly legal and makes 100% sense that I should > be able to call $lazy->sayHi() and it calls A::sayHi(), which is what you > would expect. Instead, this is runtime error. > The reason why this doesn't work is that the RFC is about state proxies, which means properties are required to hook the lazy behavior. The RFC forbids your 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 reasoning as much as possible and this is covered. Nicolas --00000000000071c4f9061e045da0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><br><br><div class=3D"gmail_quote"><div dir=3D"ltr" = class=3D"gmail_attr">Le mer. 24 juil. 2024 =C3=A0 21:44, Rob Landers <ro= b@bottled.codes> a =C3=A9crit=C2=A0:<br></div><blockquote class=3D"gmail= _quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:= 1ex"><u></u><div><div><br></div><div><br></div><div>On Wed, Jul 24, 2024, a= t 16:28, Nicolas Grekas wrote:<br></div><blockquote type=3D"cite" id=3D"m_3= 612589975186624774qt"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><div><div= >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 = to do it to cover the use case.<br></div></div></div></blockquote><div><br>= </div><div>I'm not sure what you mean, as the RFC makes it look this sh= ould be completely legal, until you get to the end:<br></div><div><br></div= ><div>interface Fancy {<br></div><div>=C2=A0 function sayHi(): void;</div><= div>}<br></div><div>class A implements Fancy {<br></div><div>=C2=A0 functio= n sayHi(): void { echo "hi!"; }</div><div>}<br></div><div><br></d= iv><div>$container->register(proxyType: Fancy::class, factory: fn() =3D&= gt; new A());<br></div><div><br></div><div>// Now container only knows that= it needs to return a FancyClass and this is "legal looking":<br>= </div><div><br></div><div>$lazy =3D new ReflectionClass($proxyType)->new= LazyProxy($factory);</div><div>// same as</div><div>$lazy =3D new Reflectio= nClass(Fancy::class)->newLazyProxy(fn() =3D> new A());<br></div><div>= <br></div><div>This ^ compiles, it's perfectly legal and makes 100% sen= se that I should be able to call $lazy->sayHi() and it calls A::sayHi(),= which is what you would expect. Instead, this is runtime error.</div></div= ></blockquote></div></div><div dir=3D"auto"><br></div><div dir=3D"auto">The= reason why this doesn't work is that the RFC is about state proxies, w= hich means properties are required to hook the lazy behavior.</div><div dir= =3D"auto">The RFC forbids your snippet because the initializer must return = a parent of Fancy::class, which A::class isn't.</div><div dir=3D"auto">= <br></div><div dir=3D"auto">Please have a closer read of the RFC, we tried = to describe the reasoning as much as possible and this is covered.</div><di= v dir=3D"auto"><br></div><div dir=3D"auto">Nicolas=C2=A0=C2=A0</div><div di= r=3D"auto"></div></div> --00000000000071c4f9061e045da0--