Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:123525
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 2C0751A009C
	for <internals@lists.php.net>; Wed,  5 Jun 2024 18:35:40 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail;
	t=1717612604; bh=cmtClAAOGds9XwKCVQc+uAzYkmC5R6MjKHlIuH8kew4=;
	h=Date:Subject:To:Cc:References:From:In-Reply-To:From;
	b=Jr+lJxmeD8jdz04RIqryLCWGNlJY2PLfO57rXQsPi4G7eUP/qRxLGXGTDPxjXnkff
	 0DYmL7UsaXk8z8XkT9+/k8QcfKxuKXwtDKY1N5O1YGL1yWhSAR1Ni4BBVl6D5aqIWt
	 TFhPf16vOGntYIr2ZEjTeKIiZKTtoQ0LRdardOShO17rlRQb8hwhSO1UWkIXHA8DOH
	 xEyETbmndqvkunsL3m2CV7niczGLQrJPWJe6km2rx1T8FOz6o323UBxJrCg5AzSur6
	 kSojhz37tRETp8NSOvRvZaxGX249dg5LUG3rb9D1rZPw54wjEvXp+0iID8oKXq2MKn
	 FaywE/9w+TpoA==
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id EB0B9180890
	for <internals@lists.php.net>; Wed,  5 Jun 2024 18:36: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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE,
	SPF_PASS,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: <tim@bastelstu.be>
Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72])
	(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,  5 Jun 2024 18:36:43 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be;
	s=mail20171119; t=1717612537;
	bh=VJqPBcNawXSQCOSbhDJ9edhuWLiXViPdqqZX/O02OIU=;
	h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:
	 In-Reply-To:Content-Type:from:to:cc:subject:message-id;
	b=cCGarOFSMFcK5zImBFjCsYN3fADgj7gjF5/j6FCQaWvU/wGKzqHmLlPdprZFsZiho
	 UF8rKfLDkzHVGh+tly/zQIZYvGcKHdnSXTyB2COp2BG4oP8pFTziPw3m4k7Fq4hlR3
	 ZHtZ+92ewUU5Ii/Ad07lIAOOS5GVP07cdGhfAK7LsWYHvdEyMrHgBcmmWNEG+krHty
	 /K9TRDa1lVm29r3CCl9rmmCMeCktViicMO9X0pKwCjqpzcWMiSudVYjpBPTNrZ1Jq/
	 RBDjyVYNHAtLZKpcrO7npIP/uIiWm9F5GPtlUVoftX1MoL+d2KqdtO/XT+iFkfoAZz
	 BBUl3JydZ5X4A==
Message-ID: <91795c9f-d6e1-4090-afb3-34c197df6e7c@bastelstu.be>
Date: Wed, 5 Jun 2024 20:35:36 +0200
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
MIME-Version: 1.0
Subject: Re: [PHP-DEV] [RFC] Lazy Objects
To: Arnaud Le Blanc <arnaud.lb@gmail.com>,
 Larry Garfield <larry@garfieldtech.com>
Cc: php internals <internals@lists.php.net>
References: <CAOWwgpmbq5VRrZQvUXDsKiNK4r6+bFA4VxnjQ_U=h8T9r0o3DA@mail.gmail.com>
 <ab83af79-0669-47dd-a3cb-ab72327ae174@bastelstu.be>
 <CAP1Jc13JWVg99AULgzrGXcoCWJtJZGz+nr_VoyUocw8n5n5sfQ@mail.gmail.com>
 <c77832b9-4143-43aa-a71b-eb9d888725e9@app.fastmail.com>
 <CAP1Jc12ZwcMS87D2f2r0NwyGJgWxbxEHMa_V7rc8Mjespavt+A@mail.gmail.com>
Content-Language: en-US
In-Reply-To: <CAP1Jc12ZwcMS87D2f2r0NwyGJgWxbxEHMa_V7rc8Mjespavt+A@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=)

Hi

Thank you Larry for your email. Your suggested API is basically what I 
also had in mind after Arnaud's clarification.

On 6/5/24 20:06, Arnaud Le Blanc wrote:
> I think you got the two strategies right. However, there is a use-case
> in which an object manages its own laziness by making itself lazy:

What is the corresponding real-world use case for that? When would I 
want to create an object that makes itself lazy?

FWIW: If I understand it right, this use case would be supported by 
Larry's proposed API by writing a named constructor:

     class C {
       private function __construct($foo, $bar) { }
       public static function lazyNew(...$args) {
         $r = new ReflectionClass(self::class);

         return $r->newInstanceWithLazyConstructor(fn ($o) => 
$o->__construct(...$args));
       }
     }

>> It also suggests that perhaps the function should be using $this, not $foo, as it's running within the context of the object (I presume?  Can it call private methods?  I assume so since it can set private properties.)
> 
> The function is not running in the context of the object. It can only
> access private members via Reflection or if the closure was bound to
> the right scope by the user. This should not be an issue when the
> initializer just calls a public constructor.

Please clarify the interaction with visibility in the RFC.

Best regards
Tim Düsterhus