Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124573 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 CAD091A00B7 for ; Wed, 24 Jul 2024 14:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1721830514; bh=qIG33ZXn8/qobUZl94O+I6XvcwZYKVwwID+zDNzbSik=; h=In-Reply-To:References:Date:From:To:Subject:From; b=CPMp94Mqo6zXcOq6Kdykjq2DKLYfrMNG8bNn7WWiShl5cSEHuJWDfDDhWrwoF46MI 3wv+8WFdyC5XD69UiVAVhAEHxTVlueCt0LgAcZi1kG6nSSBC6Lu9S3Rewwqi7OzFyw w5A505l804V7lSPBWudURSNqC0xxLsQiMJ9DiAe7VM3wQu7Ue6koJS0vKIBUX2JXb0 1mo0ntfD3GgvWYe4BGj8pbiqv96IYxXaFzTaAMlxaE2rZx9xFMUhEaKvrK1dAAgd/h jI88VW9Gnw1yR8LZ5i5+FymmJUA064T4AwSEshboTMn5wVNl0owr2TaEDsrApE10Ih SQSS9VEAKCBNA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0B58C180056 for ; Wed, 24 Jul 2024 14:15:13 +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_H4,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 fout8-smtp.messagingengine.com (fout8-smtp.messagingengine.com [103.168.172.151]) (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 14:15:12 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 67B571380094 for ; Wed, 24 Jul 2024 10:13:36 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute3.internal (MEProxy); Wed, 24 Jul 2024 10:13:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=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=1721830416; x=1721916816; bh=c0lxNfq9/G 7hB5pa+S/Bub78WN0OCE1OMKC/2benKbY=; b=rj/76ydEuGwqdhHIo64+z1hWu0 9M1aaNNG16248Fmkf0DjMgI/IU2Za7DQ1BpUqP2BQfeOfahIRiJHtN+Uhcd+EfCW PvRtK3g1IYDFK21yi+PMD2l7HamwLztxfeLHPe7eAJ4QSzfDAEmG39Rr7H6i++h+ t289/lTNRGawhxS7V0djbtkaOF3d+4eZiprxCjbc4Qjr/rXoyte++TNkRykKyvVB 5xhh+xie9+jiO1OLit4sLeHuEZjT3b6ZapjFXzQ0kXOnQdv3VlJyGd2TygXxEObP je/nS16NJq23IJjzGcCm5XfxxjMOxUiNl5M0q5DGVeThWxkbdAER3Ak7E3Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1721830416; x=1721916816; bh=c0lxNfq9/G7hB5pa+S/Bub78WN0O CE1OMKC/2benKbY=; b=UspdKX0i205nCf66fm/TXdGRTVxEEVpLB9pcnTHbfw8P ms9RgnAGkuAN9GASm0DANVOllE5acf0SM02pVZOMMMGU6z+fBepkO9gLTBi3EK6O Dv92eQo2/zv8l29peKN2uZcYI/Ty6KnxXZ8JIK0/1P7gucoqfIMabdigXxG+J5Qn r5exSoRLP3atBCMS5PG5mWtG9hNMorp2KV4LkB5LaLj7IFHl5ZAKum4eXXMAojnt boeEFm8HshD1t4PZ0BW3CG2H6Y36wYpqgxAEREwiD/tjbgthjDezHD5QSMiNcGS6 nC9QFprRl6OxlU5uHBl9PkvsaK79SHSNONUzxGa+Hg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddriedugdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesrgdtre erreerjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhl vggurdgtohguvghsqeenucggtffrrghtthgvrhhnpeeffeduhfduudeikeekudfghfdugf eljefgkeeghfdvieekledvvdejheetgeetgeenucevlhhushhtvghrufhiiigvpedtnecu rfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsg gprhgtphhtthhopedt X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 22C0715A0092; Wed, 24 Jul 2024 10:13:36 -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: <138f79e3-20cb-441f-8899-bdf40ef0868e@app.fastmail.com> In-Reply-To: <2fd6d80d-a55c-4aad-aeee-6d07d4b930a1@app.fastmail.com> 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> Date: Wed, 24 Jul 2024 16:13:01 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] Lazy Objects Content-Type: multipart/alternative; boundary=91691daf5bcc4889b83c84650d766046 From: rob@bottled.codes ("Rob Landers") --91691daf5bcc4889b83c84650d766046 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jul 24, 2024, at 16:02, Larry Garfield wrote: > On Thu, Jul 18, 2024, at 7:12 AM, Nicolas Grekas wrote: >=20 > >> Otherwise, I'm quite looking forward to this. > > > > =F0=9F=A4=9E >=20 > Another thought that occurred to me. Given how lightweight it *looks*= to be (may not actually be, but looks it), how much overhead would ther= e be to having a compiled DI container that is lazy by default? Just ma= ke everything lazy with a fairly standard initializer or factory, unless= a specific case says you shouldn't. That way you can use optional depe= ndencies in a constructor pretty much at will with no overhead of needin= g to create a chain of dependencies as a result. >=20 > Would that be a bad idea for some reason, or would it actually work? >=20 > (This doesn't really affect my vote, more just a thought that came up.) >=20 > --Larry Garfield >=20 I'm not convinced a DI container is possible at all with this implementa= tion, see "surprising behaviors." When you are building a DI container, you usually have *absolutely no id= ea* what a user will return from a proxy. At most, you might know they a= re returning SomeInterface or SomeBaseClass, but the user might return M= yFancyClass that implements the interface or base class, which isn't all= owed via this implementation. The type must be exactly the same or a par= ent class: > the factory of a lazy proxy is allowed to return an instance of the sa= me class as the proxy, or of a parent class. >=20 > Returning an instance of a sub-class is not allowed =E2=80=94 Rob --91691daf5bcc4889b83c84650d766046 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Jul 24,= 2024, at 16:02, Larry Garfield wrote:
On Thu, Jul 18, 2024, at 7:12 AM, Nicolas Gr= ekas wrote:

>> Otherwise, I'm quite l= ooking forward to this.
>
> =F0=9F=A4=9E=

Another thought that occurred to me. = Given how lightweight it *looks* to be (may not actually be, but looks = it), how much overhead would there be to having a compiled DI container = that is lazy by default?  Just make everything lazy with a fairly s= tandard initializer or factory, unless a specific case says you shouldn'= t.  That way you can use optional dependencies in a constructor pre= tty much at will with no overhead of needing to create a chain of depend= encies as a result.

Would that be a bad ide= a for some reason, or would it actually work?

(This doesn't really affect my vote, more just a thought that came up= .)

--Larry Garfield


I'm not convinced a DI container is po= ssible at all with this implementation, see "surprising behaviors."
<= /div>

When you are building a DI container, you usual= ly have absolutely no idea what a user will return from a pr= oxy. At most, you might know they are returning SomeInterface or SomeBas= eClass, but the user might return MyFancyClass that implements the inter= face or base class, which isn't allowed via this implementation. The typ= e must be exactly the same or a parent class:

the factory of a lazy proxy is allowed to r= eturn an instance of the same class as the proxy, or of a parent class.<= br>

Returning an instance of a sub-class is not= allowed

=E2= =80=94 Rob
--91691daf5bcc4889b83c84650d766046--