Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123523 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 159631A009C for ; Wed, 5 Jun 2024 18:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1717610881; bh=pz1Xx0hHJcGC56lX04U3gd1pf/+bJBZTA4VSvk6/iN0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IR3nPAgyHxiUqw7DT7dGp1FPNOPDaTEeajWSy+d6BU36Ckb53SwMWWG7DIRhJrthh uoQd2OybN4gfTLJRRwdt4k1CjU9S4vAcQKHWBE1SYUP0eKtPhjJFe0EWzOQVjOuT+D s7+sugUyoJ8tncX1mXcRUNS+NVc2hZVOSdlBzpZsFok7NijfQcDDxdll04elfwJycx rDaXuXG6gfRh6uaqNPXV1X4HjYjw2kIqV6CDJmVWIt9xrvAb/eiiEIOyaa+uwHV7AD o+2XG77uRdLdheDyZ1WMtnhgt0qRnS25ZTQzfIwcXY9DNR0gmMB12PFHMvK9N9wipB MrBiNnFWUuKdA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 78E2918076F for ; Wed, 5 Jun 2024 18:08:00 +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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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, 5 Jun 2024 18:07:59 +0000 (UTC) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a62ef52e837so13736366b.3 for ; Wed, 05 Jun 2024 11:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717610814; x=1718215614; 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=mGLMr5lNwGV/8fVD6dZmGaeAw2GKaGc2M/bzV68zh1g=; b=eRsC+0bRcP1n/G4Y+/kGJ9ZX/a/PL2FDD7VxHvfnxJc0ryHtfYUlz4FcAEvkEoIpBi hmueyluWae85j1lKQfEK8IQ1yCW3xhNFpEl+uE8sbWeRmvT+TPWJjn9u5Gk+LXx2p1sN RhCaqnIaQA2fWImzfeuU2BoSsSdcBXvjdY9X5XjEMnbaIu6ZUY2sDbTTC71w2Dxh+Vhy 7EYMHa54qosX1vvSU8n/AVvuZBwL6jfa66EKv434kRR6+iPjoCGbYRUuIa9CQT6vAFZj IryQFSMZl9Kd6PzjBmldCbWIUyYHCcC6Rv3QyyoBtegFzTEb1ZNtzVDCeK1Guo9fHdFv 7v0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717610814; x=1718215614; 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=mGLMr5lNwGV/8fVD6dZmGaeAw2GKaGc2M/bzV68zh1g=; b=UZ0ak8dNUQviWJyDS8eAeDm9IotjnOcb3YGq0T38KTBdNaq+4ZAPeZlY4PyuukTrwh Y6UQE91tfcamf3gBjMUtHqgN04he/qdQGmSySNVOUwrfYcTOyR4o0tfhyUPDOINvzWLz ZXDyNMocco71ocoeXqaWmmd/9zE/eQbYe20JQiJONyWRiK7rHQhmppN682626TEKb0at rmGEmdiZop1TWuhUdZOlcT/EQLKKEJ8nPj+fnn/T/XyayDCv+7tlrJS/Ts52Ss7j0xlp hJcmwQ+xu7eEkKxog0ehtwGoGc16zKAqVA4EcOhT8usgiZsJJGifnZTpVG6j5H9ZogdZ 5vsA== X-Gm-Message-State: AOJu0YwSA5JrmL9IKWz2LM+dPnbYw5oNmzhuOwEKRqV9vE0Nru7XMKHe CjBny/ep6XuaYUlTnyagdH4HYIP9ODwIbOUNgOfXf98DbSWsq9CIJjgk/OnkDv5l5Sc4T31d2Wv lasDtDEGkBgO1K8kllgTd+mZCmSM8r8b6 X-Google-Smtp-Source: AGHT+IHete5rmsPo/v6Jrwl+W7avRok4csBCLYLuF4YoRXg/SPQfHFwkolEjTEAcVp3TA+1RU8TLIvfcxdmU2lMxmlQ= X-Received: by 2002:a17:906:f28f:b0:a68:dff5:b153 with SMTP id a640c23a62f3a-a699f67ecddmr224307466b.33.1717610813638; Wed, 05 Jun 2024 11:06:53 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 5 Jun 2024 20:06:42 +0200 Message-ID: Subject: Re: [PHP-DEV] [RFC] Lazy Objects To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Larry, Thank you for the feedback. 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: ``` class C { public function __construct() { ReflectionLazyObject::makeLazyGhost($this, $this->init(...)); } } ``` This one can not be addressed by a newInstance*() method since the object to be made lazy already exists. The makeLazyGhost() / makeLazyProxy() methods are the minimal methods necessary to address all use-cases, but the methods you are suggesting are a better API most of the time, so we are adding approximately this to the proposal [1]. We are keeping them in a separate class to not pollute ReflectionClass. > 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. > In which case $object is the proxy, and gets "swapped out" for the return value of the $initializer on first use. Just to be sure: $object continues to be the proxy instance after the initializer is called, but it forwards all property accesses to the return value of the $initializer. [1] https://news-web.php.net/php.internals/123518 Best Regards, Arnaud