Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125023 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 BAF5F1A00BD for ; Sat, 17 Aug 2024 05:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723873121; bh=Y4JjdHFr+ok4C+HAzTDSv8MMXJESt8epnf0o/kUj6r4=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From; b=Z6c+67XEXxfm0acBbVMbfd7LdjlGPGtB2eZz8D3nQh3E+hYeEbm6vj5wa40iPVtLb 7dnhozbGJwiWN9+xqpNbdiBiZPqKtpuEc9mjuCR5xNnw4SSQO50RI9B6psb+Hq2u1Z oPXhBml0X3dCMgaD9dlxY47NvC+B38CrIf4zHtngqOJDsYkhlzzqf8x64UkFEkIVb4 FUY6dAoKq+QsXwCBqshuUWUohd9YUDFHWox1nXIgaqpblz/B4T/oFZblh2E9V2pPAD sFXvYo3cToId+o2rS1F439oRSCqP2FJ1vpa5yu3itUDWnNPiKgblC/yXeWz/mm9bdO Ojcwgvp6vIHmw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96C6E180072 for ; Sat, 17 Aug 2024 05:38:40 +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.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_SOFTFAIL,STOX_BOUND_090909_B autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from serval.cherry.relay.mailchannels.net (serval.cherry.relay.mailchannels.net [23.83.223.163]) (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 ; Sat, 17 Aug 2024 05:38:38 +0000 (UTC) X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id C10B0365870 for ; Sat, 17 Aug 2024 05:36:50 +0000 (UTC) Received: from nl1-ss105.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id B432536584F for ; Sat, 17 Aug 2024 05:36:49 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1723873010; a=rsa-sha256; cv=none; b=HYvcJ6f3okaH44FTy49HqLczsPztCoXmvF4wVwcCplgJwJs+CJ67tlGDtzEXnB9wz/6iB5 kzHqvTshF1vHjkT4uhVxQrTV5GoLmSsBbsnpb+xEfhEvOaNXLcI3CvpbSwMpXmHdPj8TVD CpZaHbyq/DrqFicMIpcJSuezFX8xUO9q9vxhsnXWQ6rFGIBGRrGpmXpmPuA0dGlrYdAMaJ xAY/O5T+7AGdxvhGtuPGShom/sBxJyWvLC/Zk6hfxQ+O07XB7+JGKxS3nK+RimAgKKiSdb dqMDDsT10QT3OrR1p19bZysM9vDWq8OavkVWiIGDKNJNbKefGaz9peE2UBnOpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1723873010; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cWpmoy2DzzftK8mv0KY932EHsDLiHApU6bDrTvs1Vjc=; b=k6VKM5B6Kr6p0hn7sOV68zNu931HJ73jn6k1YBecySWf3CeOvQnJi4wWogFlx3+LR5lFhq YQ/Z0lc9yyr0hPVh2aYXeuezWuDiseHX2bAzMq1LJZoLJ9zTAdKAgu3aPnhDGl3bDrnwhT 3Eqg/xUYOmQVXQdV9yg8G1xNOm4CUHiS3p3XrR5EtlpFON/q/T93cTDT7O6fy4TReEgbiX tqqfBcBYU8W4hlI9lUvHqqBA6ZV5c0d3blIAH88znJqT7xM0BjbnBTEv+fygtb9F7zkqJZ NPxVdgu5rkJf5XIEY2xZgXQ+lF14S2x5SbZxz70D8CAgCqDGMP8Bj6MLhC2+6Q== ARC-Authentication-Results: i=1; rspamd-587694846-bwmb2; auth=pass smtp.auth=a2hosting smtp.mailfrom=php-internals_nospam@adviesenzo.nl X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|juliette@adviesenzo.nl X-MailChannels-Auth-Id: a2hosting X-Decisive-Exultant: 2a1a459b50d91811_1723873010273_566928095 X-MC-Loop-Signature: 1723873010273:1383158400 X-MC-Ingress-Time: 1723873010273 Received: from nl1-ss105.a2hosting.com (nl1-ss105.a2hosting.com [85.187.142.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.117.75.39 (trex/7.0.2); Sat, 17 Aug 2024 05:36:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=adviesenzo.nl; s=default; h=Content-Type:In-Reply-To:MIME-Version:Date: Message-ID:From:Cc:References:To:Subject:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cWpmoy2DzzftK8mv0KY932EHsDLiHApU6bDrTvs1Vjc=; b=a+tfPSRSTfL/Yf7Lvndcw22/Vo QqojhFygyejDkjVVhTR9oSHXrhxIkxfzfqYxO1pV2t+fh1dxYkiqQrbhIzYf6y3aO0rTjwn0PqNhx 4mg3Fe1pMNobvJJx1GWRyBZizBwExVlQQPfsUkG992CfStpPj+1Uy8x8pvoE+kl0Dty0=; Received: from mailnull by nl1-ss105.a2hosting.com with spam-scanner (Exim 4.97.1) (envelope-from ) id 1sfC7L-0000000FEa8-3PwF for internals@lists.php.net; Sat, 17 Aug 2024 07:36:47 +0200 X-ImunifyEmail-Filter-Info: UkNQVF9DT1VOVF9UV08gVE9fRE5fQUxMIFJDVkRfVklBX1NN VFBfQVV USCBSQ1ZEX1RMU19BTEwgU1VCSkVDVF9FTkRTX1FVRVNUSU9OIFZFUk lMT0NLX0NCIE1JRF9SSFNfTUFUQ0hfRlJPTSBCQVlFU19IQU0gRlJPT V9FUV9FTlZGUk9NIFRPX01BVENIX0VOVlJDUFRfU09NRSBGUk9NX0hB U19ETiBNSU1FX1RSQUNFIFJDVkRfQ09VTlRfT05FIElFX1ZMX1BCTF9 BQ0NPVU5UXzAxIEFTTiBBUkNfTkEgTUlNRV9VTktOT1dO X-ImunifyEmail-Filter-Action: no action X-ImunifyEmail-Filter-Score: 0.64 X-ImunifyEmail-Filter-Version: 3.8.4/202408161000 Received: from [31.201.40.213] (port=58081 helo=[192.168.1.16]) by nl1-ss105.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.97.1) (envelope-from ) id 1sfC7M-0000000FEZv-34Uw; Sat, 17 Aug 2024 07:36:47 +0200 Subject: Re: [PHP-DEV] Should there be a `get_declared_enums()` function ? To: Mike Schinkel References: <66BD5F05.8010409@adviesenzo.nl> <8dc51539-20bb-4017-b859-76066e2287e5@gmx.de> <4AA66A3E-1ACF-48F5-81A2-C6AAAE8B3FD0@newclarity.net> <66BFFC0C.1090900@adviesenzo.nl> Cc: PHP internals Message-ID: <66C036DA.6090801@adviesenzo.nl> Date: Sat, 17 Aug 2024 07:36:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------070503010005030407070303" X-AuthUser: juliette@adviesenzo.nl From: php-internals_nospam@adviesenzo.nl (Juliette Reinders Folmer) This is a multi-part message in MIME format. --------------070503010005030407070303 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Mike, > >> There is one problem I can see with this approach though: since PHP 7.4, the return value of `get_declared_classes()` (and friends) does not guarantee any particular order anymore [2]. >> So, an `array_slice($symbols, $n)` may not get you the _latest_ classes loaded, so I think this would only work if the order of classes is guaranteed in some way. > That is a super relevant insight and one I was actually not aware of. > > Do you happen to know if it was triggered by an explicit RFC to that effect, or if it resulted because of a side-effect of some other implementation change? I honestly don't know, but if I look through the PHP 7.4 RFC list, I have a niggling suspicion it may have something to do with the Preloading RFC [1] ? I may very well be wrong though. > From my perspective, that is definitely a BC break and one that I am surprised I never noticed before? Do you also know if it is a case of "not guaranteed, but in-fact actual fact it always works that way, or not?" Well, for the autoloader I previously linked to [2], it was a problematic change which we did have to work around, see [3] and [4] for details of the issues we saw (parent class vs child class order reversals, issues when multiple classes were declared in one file). I haven't deep-dived into the order change, other than to validate the reported issues and proposed fixes. > What if instead PHP were to implement an optional 2nd callback parameter to `include()` / `require()` / `include_once()` / `require_once()` to allow us to capture the symbols loaded and their paths? The callback function could return `void` and accept an array of `$symbols` with the following guaranteed minimum structure? > > $symbols = array( > 'classes' => [], > 'interfaces' => [], > 'traits' => [], > 'enums' => [], > ); Except `include()` and friends aren't function calls, but language constructs/expressions and don't take parameters as such, so I don't see how that would be possible without changing `include()` and friends to function calls (along the lines of what happened for `exit` in PHP 8.4 with non-parenthesized use still possible to mitigate the otherwise huge breaking change), or alternatively, introducing wrapper functions for the language constructs - so no change to the existing functionality, but new functions with a signature along the lines of `include_and_get_symbols( $path ): array` with the return value being the symbols loaded from $path. > This approach would be a less disruptive than my prior suggestion Not so sure about that considering the above ;-) > What do you think if this alternate approach? This probably needs some more bike shedding ;-) Smile, Juliette 1: https://wiki.php.net/rfc/preload 2: https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/6fbbc1078094d905f0773421f13830744a144d1e/autoload.php#L153-L247 3: https://github.com/squizlabs/PHP_CodeSniffer/pull/3130 4: https://github.com/squizlabs/PHP_CodeSniffer/issues/3145 --------------070503010005030407070303 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Hi Mike,


There is one problem I can see with this approach though: since PHP 7.4, the return value of `get_declared_classes()` (and friends) does not guarantee any particular order anymore [2].
So, an `array_slice($symbols, $n)` may not get you the _latest_ classes loaded, so I think this would only work if the order of classes is guaranteed in some way.
That is a super relevant insight and one I was actually not aware of.

Do you happen to know if it was triggered by an explicit RFC to that effect, or if it resulted because of a side-effect of some other implementation change?
I honestly don't know, but if I look through the PHP 7.4 RFC list, I have a niggling suspicion it may have something to do with the Preloading RFC [1] ? I may very well be wrong though.

From my perspective, that is definitely a BC break and one that I am surprised I never noticed before?  Do you also know if it is a case of "not guaranteed, but in-fact actual fact it always works that way, or not?"

Well, for the autoloader I previously linked to [2], it was a problematic change which we did have to work around, see [3] and [4] for details of the issues we saw (parent class vs child class order reversals, issues when multiple classes were declared in one file).

I haven't deep-dived into the order change, other than to validate the reported issues and proposed fixes.

What if instead PHP were to implement an optional 2nd callback parameter to `include()` / `require()` / `include_once()` / `require_once()` to allow us to capture the symbols loaded and their paths? The callback function could return `void` and accept an array of `$symbols` with the following guaranteed minimum structure?

$symbols = array(
   'classes' => [],
   'interfaces' => [],
   'traits' => [],
   'enums' => [],
);

Except `include()` and friends aren't function calls, but language constructs/expressions and don't take parameters as such, so I don't see how that would be possible without changing `include()` and friends to function calls (along the lines of what happened for `exit` in PHP 8.4 with non-parenthesized use still possible to mitigate the otherwise huge breaking change), or alternatively, introducing wrapper functions for the language constructs - so no change to the existing functionality, but new functions with a signature along the lines of `include_and_get_symbols( $path ): array` with the return value being the symbols loaded from $path.

This approach would be a less disruptive than my prior suggestion

Not so sure about that considering the above ;-)
What do you think if this alternate approach?

This probably needs some more bike shedding ;-)

Smile,
Juliette


1: https://wiki.php.net/rfc/preload
2: https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/6fbbc1078094d905f0773421f13830744a144d1e/autoload.php#L153-L247
3: https://github.com/squizlabs/PHP_CodeSniffer/pull/3130
4: https://github.com/squizlabs/PHP_CodeSniffer/issues/3145
--------------070503010005030407070303--