Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123607 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 9C0AF1ADC1A for ; Fri, 14 Jun 2024 20:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718396221; bh=uGEILYbLkE/+RpR/qfZdK8wkULNJ3fwjSJz32sCb0cQ=; h=In-Reply-To:References:Date:From:To:Subject:From; b=XCEdmDljvSFlOUz859ZybMW6FM3xq+gSGoxk9rwlRI1I1SESeUz0UdmRLauU/BN64 30KatRCHpT8G9bUsDbKcEedamtDYLlZwDTPzCkbhUYMnHk5zCItgWVVdeTrslhze30 EUApnmmmmBUdA8vdXuXO9bY2lEFX+CdcD3OPUvUXKWsbnEEe2e/8bKFgFi5ZQhfZvB a9A5qLbCVWie7Vvf0S6JbpkrJ1yxTJkFugS2MT/YWphGE9iQsC2TwJM5JWCC18KukE oM7nSUENjX/1ZH3sxjJ7GnDeuFubfNE0Kx5ng4fftRpUXc1P//zExppNYzRXQwmR9a 34vtkbjZhTbyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E71A41801EB for ; Fri, 14 Jun 2024 20:16:58 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 ; Fri, 14 Jun 2024 20:16:57 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 5A32B1380158 for ; Fri, 14 Jun 2024 16:15:46 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Fri, 14 Jun 2024 16:15:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=1718396146; x= 1718482546; bh=vYdtQ05JK0I09c1006hQkEOJrZNvEMGPuNxfSe2pA2Y=; b=q 0RyQ31Bi23t/GfQaAvJ0wkH5lLGp1geW+RX9wWv/fN2OHb8jm4dRF4LgJG1r5Tbv PTaz1Wnrb2yu0Mvci3quiExkBAGkOnbMIUTtTckllbK68R2KxsNpAs9HkgcxDZ+s vYuB3rXP3bx5Lpf+dvoL21WbOlDqy9YAkdLuwSx/h5VcuWT6AmyY85TpZa1YFe7A OWHopDkMxC/S+E1PZojpbxODAUm054mWjyDmjVJ8Qx+lwLjpycxpspiD0G5AsMed 5gy3BJy6OO0gaexyZpHOFqifzBkul1pQxfg4/3Z0zqqGpMOx/Vf27fwXegDZfoXE 55m8FSfqZCjyGUIsVFEmQ== 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= fm1; t=1718396146; x=1718482546; bh=vYdtQ05JK0I09c1006hQkEOJrZNv EMGPuNxfSe2pA2Y=; b=FdkS35OWGChY2X5UQPMWsq2ARNVEoNhu0/cW2MW76lTx m+sZDRqRO6xU9MgdI8a/HOrthwtAhLJQE9O0zYouhP7lreFH2fyLtc3jGUMtfyB1 Q0lm1X4mDFf8/Ow2ORr3kFOSLkZ/6woZeiUY8ra7cgE4QNYvxGYA1K3nYMuxdVLw bObdaYyquJ98++/Q/ucRl2usB9fzAfRgixXaxe+NhqwE1/RWKn5Tyyr3tq6M2TQ7 umGWawFST1exD7N1Wn3rwQwhQb0ESEHsjcZO3Hlc6N98h59w9haEAof53QULA35i 2Rp5aKuCiR5CShkNeeTOAb+DjP2fxXfvpytbw8ezdQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduledgudegiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 09E351700093; Fri, 14 Jun 2024 16:15:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-515-g87b2bad5a-fm-20240604.001-g87b2bad5 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: <1118bbcd-a7b4-47bf-bf35-1a36ab4628e1@bastelstu.be> Date: Fri, 14 Jun 2024 20:15:25 +0000 To: "php internals" Subject: Re: [PHP-DEV] [RFC] Lazy Objects Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Fri, Jun 14, 2024, at 12:13 PM, Arnaud Le Blanc wrote: > Hi Tim, > > We have updated the RFC to address your feedback. Please find > additional answers below. The updated RFC looks much better, thank you. Though I still have some thoughts, in no particular order. > The actual instance is allowed to escape the proxy and to create direct references to itself. How? Is this a "return $this" type of situation? This could use more fleshing out and examples. The terms "virtual" and "proxy" seem to be used interchangeably in different places, including in the API. Please just use one, and purge the other. It's confusing as is. :-) (I'd favor "proxy", as it seems more accurate to what is happening.) For that matter, I'd be very tempted to remove the word "lazy" from the API calls. `newGhostInstance()` and `newProxyInstance()` are plenty understandable, and shorter/easier to read. (Similarly, `makeGhostInstance()` and `makeProxyInstance()`. Although since those are more about modifying a provided object to be lazy, perhaps "make" isn't the right verb to use as that often means "create".) Under Common Behavior, you have an example of calling the constructor directly, using the reflection API, but not of binding the callable, which the text says is also available. Please include an example of that so we can evaluate how clumsy (or not) it would be. > After calling newLazyGhostInstance(), the behavior of the object is the same as an object created by newLazyGhostInstance(). I think the first is supposed be a make* call? > When making an existing object lazy, the makeInstanceLazy*() methods call the destructor unless the SKIP_DESTRUCTOR flag is given. I don't quite get why this is. Admittedly destructors are rarely used, but why does it need to call the destructor? I find it interesting that your examples list DICs as a use case for proxies, when I would have expected that to fit ghosts better. The common pattern, I would think, would be: class Service { public function __construct(private ServiceA $a, private ServiceB $b) {} } $c = some_container(); $init = fn() => $this->__construct($c->get(ServiceA::class), $c->get(ServiceB::class)); $service = new ReflectionLazyObjectFactory(Service::class, $init); (Most likely in generated code that can dynamically sort out the container calls to inline.) Am I missing something? ReflectionLazyObjectFactory is a terrible name. Sorry, it is. :-) Especially if it's subclassing ReflectionClass. If it were its own thing, maybe, but it's still too verbose. I know you don't want to put more on the "dumping ground" fo ReflectionClass, but honestly, that feels more ergonomic to me. That way the following are all siblings: newInstance(...$args) newInstanceWithoutConstructor(...$args) newGhostInstance($init) newProxyInstance($init) That feels a lot more sensible and ergonomic to me. isInitialized(), initialized(), etc. also feel like they make more sense as methods on ReflectionObject, not as static methods on a random new class. As I said, definitely improved, and I like where it's going. I think it can improve further, though. --Larry Garfield