Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124954 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 294681A00B7 for ; Thu, 15 Aug 2024 18:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723747322; bh=yMyrkKNJwpgDSI9mKrFERRYG3H7W7Kkh+bLEysNGzy0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Cf4Lgy1swiy1Me+9r7N3Gi3TdiErF8f+4sIajntLczjbXSgMfc5SR5wa2EjAAeCzQ +IgkaEjD/xQrKLhQ/CxQcEo7Ktr2XAvtb+c/akz5KcOQluSBi8GJ6Yam1ZetjqC8zA Rqsw2aCyGF5N7JqI2LatGSX3JvuphoMAvmm6FlOg7QJL7m2F5d1yTrdjsDHB/z2KTw 7ASd8wRnLD1AA0hHY9wGYK2PfWAeGUsBT4CcBqS1Oyxute9NJm/UWzJ9ZaqpaqIiF+ 0qc5rBF9mAxoh6NskqEsypY3/TjW2Y48rE2H5gT6X9tykBC/KKBZ4rzW/99hIzmvvf NgBuUbH8YQzxQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 028B7180077 for ; Thu, 15 Aug 2024 18:42:01 +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,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 ; Thu, 15 Aug 2024 18:42:00 +0000 (UTC) Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 692A111519E2 for ; Thu, 15 Aug 2024 14:40:13 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 15 Aug 2024 14:40:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=fm3; t=1723747213; x=1723833613; bh=6P+68T1RoI 81Eyft/uwpjmf/mfyBFKbxdGGY06RwZOI=; b=n76/Q3R8zOUkyCvjQJzaQMKeB4 NB6ksGUCmC3AmE1v9+5YYs0/ZpwIR3clT/c/rkpE5wTsf6IZygFhnvDhJ6Mc81r8 XERYhnH8OaXredce9LZWQYy+SuenJLi7KGsmfcJakGIJwfGNu8C0P814gscAqSsO 6xxwkn1E2JrsvJBKeMNmkO9KMnJvv7bCCRj21r8xwzZqRUuEleabYIUtdn8xcCEg qeoYSSuMA2ilwWtWWj4DDMS31O7Um7TGqltHzUnW/GocZUNyyX80iweRdHMnPc0q dnvCbMcRFm0oqC6T9D47oZ3uODlycotVnG/LkHK1me6X3BwkTR8Nv12cgz/g== 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=1723747213; x=1723833613; bh=6P+68T1RoI81Eyft/uwpjmf/mfyB FKbxdGGY06RwZOI=; b=NyUSWojJdEeOIXU6PsAvDFB7uPQP8khW7aXWKs0DVHy0 Wzc0ye74ypBc3FOUzNXcoly5Vsb0Qi9iBG/ABlYyKsRtVueWAq29hdyKnc2IsFFz aSwd3tCcvpQbIDxvkFm7HuXSt6J5l+OW77mCnhTjnMy1+ZqwxKLEZHOEAmvjaabX eJo3Wid63i01fVKprc0J5Gh97vYv4NmRB97K37phe4B+Tp95ETV0g07lwFfxhwCZ KBbvvp08zKQa4iURI5SROAzRQJBesEgsr1yK+FX08o8dhEisDxMWWrhdh2EnnA4Y L2ofnCX/UUCkF2XLAFYeo1/qfk9WYJfLkk1aGeBI2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtiedgudeftdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkff ggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhn shculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenuc ggtffrrghtthgvrhhnpeeggffhvdegfeeuffetkeekleefuddvgeejteduveevteegvdef jeelfeegtdekveenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdr tghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 15 Aug 2024 14:40:12 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------02oZ7SL0jdxKG4PPAIgZ8G8V" Message-ID: Date: Thu, 15 Aug 2024 19:40:11 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] function autoloading v4 RFC To: internals@lists.php.net References: <2716f729-4008-4f75-8412-861d8960b746@app.fastmail.com> Content-Language: en-GB In-Reply-To: <2716f729-4008-4f75-8412-861d8960b746@app.fastmail.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------02oZ7SL0jdxKG4PPAIgZ8G8V Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 15/08/2024 16:22, Rob Landers wrote: > Hello internals, > > I've decided to attempt an RFC for function autoloading. After reading > hundreds of ancient (and recent) emails relating to the topic along > with several abandoned RFCs from the past, and after much review, I've > decided to put forth a variation of a previous RFC, as it seemed the > least ambitious and the most likely to work: > > https://wiki.php.net/rfc/function_autoloading4 Hi Rob, While brevity can sometimes be a virtue, I feel like there's a lot left to the reader's interpretation here. Specifically, one of the main issues that has come up in previous discussions of the topic is the behaviour of unqualified function names, which check the current namespace first, then fall back to global scope. Your RFC implies an approach to this, but doesn't actually spell it out, nor discuss its pros and cons. The fully qualified case is straight-forward: the autoloader is called, and if still not defined, an error is thrown. But for the unqualified case, there are multiple scenarios, and you only give the behaviour for one of them: Defined in current namespace? | Defined in global namespace? | Proposed behaviour ------------------------------+------------------------------+-------------------------------------- No                            | No                           | Autoloader called, with prefixed name No                            | Yes                          | ??? Yes                           | No                           | ??? Yes                           | Yes                          | ??? The third and fourth cases (where the function exists in the current namespace) are straight-forward, although it wouldn't hurt to spell them out: presumably, the namespaced function is used as now, so no autoloading is needed. The complex case has always been the second one: the function doesn't exist in the current namespace, but *does* exist in the global namespace. (Or, an autoloader *defines* it in the global namespace.) In concrete terms, what does this code output: spl_autoload_register( function($function, $type) { echo "$function..."; }, type:SPL_AUTOLOAD_FUNCTION); namespace Foo {    foreach (['hello', 'goodbye'] as $word) {       echo strlen($word), ';';    } } a) "Foo\strlen...5;Foo\strlen...7;" (the autoloader is called every time the function is encountered) b) "Foo\strlen...5;7;" (the autoloader is called once, then somehow marked not to run again for this name c) "5;7;" (the autoloader is never run for this code) Note that there is an open RFC implementing option (b) by Gina and Dan here: https://wiki.php.net/rfc/core-autoloading Last I heard, Gina was still hoping to get back to it. On a different note, there is no mention of autoloading namespaced constants in this RFC, unlike in some previous proposals. Is this a conscious decision to leave them out of scope, or an oversight? Regards, -- Rowan Tommins [IMSoP] --------------02oZ7SL0jdxKG4PPAIgZ8G8V Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 15/08/2024 16:22, Rob Landers wrote:
Hello internals,

I've decided to attempt an RFC for function autoloading. After reading hundreds of ancient (and recent) emails relating to the topic along with several abandoned RFCs from the past, and after much review, I've decided to put forth a variation of a previous RFC, as it seemed the least ambitious and the most likely to work:


Hi Rob,

While brevity can sometimes be a virtue, I feel like there's a lot left to the reader's interpretation here.

Specifically, one of the main issues that has come up in previous discussions of the topic is the behaviour of unqualified function names, which check the current namespace first, then fall back to global scope. Your RFC implies an approach to this, but doesn't actually spell it out, nor discuss its pros and cons.

The fully qualified case is straight-forward: the autoloader is called, and if still not defined, an error is thrown. But for the unqualified case, there are multiple scenarios, and you only give the behaviour for one of them:

Defined in current namespace? | Defined in global namespace? | Proposed behaviour
------------------------------+------------------------------+--------------------------------------
No                            | No                           | Autoloader called, with prefixed name
No                            | Yes                          | ???
Yes                           | No                           | ???
Yes                           | Yes                          | ???

The third and fourth cases (where the function exists in the current namespace) are straight-forward, although it wouldn't hurt to spell them out: presumably, the namespaced function is used as now, so no autoloading is needed.

The complex case has always been the second one: the function doesn't exist in the current namespace, but *does* exist in the global namespace. (Or, an autoloader *defines* it in the global namespace.)

In concrete terms, what does this code output:

spl_autoload_register( function($function, $type) { echo "$function..."; }, type:SPL_AUTOLOAD_FUNCTION);

namespace Foo {
   foreach (['hello', 'goodbye'] as $word) {
      echo strlen($word), ';';
   }
}

a) "Foo\strlen...5;Foo\strlen...7;" (the autoloader is called every time the function is encountered)
b) "Foo\strlen...5;7;" (the autoloader is called once, then somehow marked not to run again for this name
c) "5;7;" (the autoloader is never run for this code)


Note that there is an open RFC implementing option (b) by Gina and Dan here: https://wiki.php.net/rfc/core-autoloading Last I heard, Gina was still hoping to get back to it.


On a different note, there is no mention of autoloading namespaced constants in this RFC, unlike in some previous proposals. Is this a conscious decision to leave them out of scope, or an oversight?


Regards,

-- 
Rowan Tommins
[IMSoP]
--------------02oZ7SL0jdxKG4PPAIgZ8G8V--