Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125018 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 80D031A00BD for ; Sat, 17 Aug 2024 01:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723858066; bh=nweC/Oy85QxY0ARU6xzgA6LZNPQNJLQc11zuJEFnbwY=; h=Subject:To:References:Cc:From:Date:In-Reply-To:From; b=PkMN57ZkrgqKmmgNmeo1MCP/TvY+8cV31w7+KmFTkpC9RdjaJuZvwVgNpqJuDxaU5 2y8PqU+0mDHHmrYnlcrdy/hA3o4k4ZwlNAnHz0Gf1TiIhN1662NO/uECjCL6zOGPyB 4Xp0LhEE/XQ6f4Hyg3tigoev5AWmKwnhTATHfu/7/hJU+U8S90kW51+ttiqNGxSXnK Zs2mdxEuw6oejuVdTmFZG8LiOK2IpifB9u2PkaXDttQv0IAhPi8FI9bR8doQRs0Qqb xGHF0tTGS6/Ii3sdlL78mEHGfr8rDoDchyLS/us29uXNq4rw5iIow4Xx+C7z2eUAiz /WTH9mIHoTC1Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D10881801D7 for ; Sat, 17 Aug 2024 01:27:45 +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=1.5 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_40, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,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 weasel.tulip.relay.mailchannels.net (weasel.tulip.relay.mailchannels.net [23.83.218.247]) (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 01:27:44 +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 C53752C54AA for ; Sat, 17 Aug 2024 01:25:56 +0000 (UTC) Received: from nl1-ss105.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id BAC522C5675 for ; Sat, 17 Aug 2024 01:25:55 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1723857956; a=rsa-sha256; cv=none; b=bjII6Hs3Y7eobPb+2GWkKgKJYJA+MYGqOPlxP+5qa7Jfd2SRNONcPAyLCxkoo+uvNzYswk ndeL9k3VZEcCcDpYeTJC8Rk4KC5XmcSA7cz/Bk4GXaZ1RMGgOCOzeu3fTQSKidADb87/0y X6s81rDT67YhBkGTMtLEnCrOJjxtEMZw7r6zlCimIt9qt2XcH/5bV29+yLKo+O0zn/DUZs TTPU9smFjPMex3A7Zgptwi/6AW0W1loIZGFYd/oR5+5jJUwS06+6s3uJEh9hKQtdmwoSkz V/RhfxOCcRiepDNQoQyD3A3LQmHWl8GA8fdBgYCjKddtJmWC4cxNCuqjOrhAgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1723857956; 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=3Uj4cOQy5a09qP0fglR+BKCBUFo6UDdbqIjIY+qU2XU=; b=p/o/fnDOpIYRi7MljjOoeCX477F1LD4HNjA8sCKte7Vzr75dMNv3834uPQTylOR3It89Kf F0If6d0PkOmC3KesVTL1bQ2yoADw0UYMWV7k4uoumWwxRNyZ5NkceEEQmjP28wOhqIK7qo /cB5b2me4zCtHUBHG7jkKhwmDS7g/Bjuyr6BdwVOH4VHu0d975A7XZlA16XzDijUpQ0rjA +n1Nk3CWIit0XCS+0eOMERY2CPl2uf2/CwMM08egxwRCch2kp/yd28ejDKaWwZGQQEKAd1 sg+/eAPdct3kuJuM2h0FVAFCELrf6ZsOQ+fYnnonmrKZKogHMtwNVZ4sQFraVw== ARC-Authentication-Results: i=1; rspamd-587694846-g59mf; 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-Thread-Cooing: 101cdc6c4d837dd5_1723857956290_1231185582 X-MC-Loop-Signature: 1723857956290:2391152132 X-MC-Ingress-Time: 1723857956290 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.126.15.104 (trex/7.0.2); Sat, 17 Aug 2024 01:25:56 +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=3Uj4cOQy5a09qP0fglR+BKCBUFo6UDdbqIjIY+qU2XU=; b=DWZAD4xfedJc/vJeySjYxRThUL V06FmdK/0CKmmD1ywUw8oPawPmcx13SocgsXYhmDFBeq4yNo5SmME7KIATYvqX63OxCfSoO1Wr3Ef aKQSBMaeKyqkGmnSSAXt59tdLEhRcFaVCkHmSOEBiOxBpBZmihuM386gkWtadBfxGv5M=; Received: from mailnull by nl1-ss105.a2hosting.com with spam-scanner (Exim 4.97.1) (envelope-from ) id 1sf8CX-0000000Afe3-3tCg for internals@lists.php.net; Sat, 17 Aug 2024 03:25:53 +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=55277 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 1sf8CY-0000000Afdq-3bAY; Sat, 17 Aug 2024 03:25:53 +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> Cc: PHP internals Message-ID: <66BFFC0C.1090900@adviesenzo.nl> Date: Sat, 17 Aug 2024 03:25:32 +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: <4AA66A3E-1ACF-48F5-81A2-C6AAAE8B3FD0@newclarity.net> Content-Type: multipart/alternative; boundary="------------090301050005050109060607" X-AuthUser: juliette@adviesenzo.nl From: php-internals_nospam@adviesenzo.nl (Juliette Reinders Folmer) This is a multi-part message in MIME format. --------------090301050005050109060607 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 17-8-2024 2:00, Mike Schinkel wrote: > To everyone on this thread and thus nobody in specific (hence my top post): > > Given that get_declared_*() populates a new ZEND_HASH each time the function is called[1] — which for classes can easily be hundreds of strings — would there be any appetite to: > > 1. Add an optional parameter — e.g. `get_declared_classes($startingFrom)` — that can limit the number of symbols starting with "n" where if n==100 then it would return array_slice($symbols,100), and > > 2. Add a function — `get_declared_class_count()` — that returns the current number of declared symbols of whichever kind of symbol, so we can get the "n" before calling `include`/`require` to use with get_declared_*() after calling `include`/`require`? > > > This would cut down on creating hashes with 100+ strings that get immediately thrown away, and also cut down on memory fragmentation/garbage collector churn. > > -Mike > > [1] https://github.com/php/php-src/blob/18d41502da0da1bb3928e60c41f1b821974c2c01/Zend/zend_builtin_functions.c#L1371 > Mike, While your suggestion does not directly relate to what triggered my mail to the list, I very very much like the idea. It's as if you are reading my mind or rather, reading one of the autoloaders [1] I need to maintain, in which your above outlined proposal should definitely make for more efficiency. Having said that, the same parameter + extra function would then also be needed for `get_declared_interfaces()`, `get_declared_traits()` - and, if it would be added, `get_declared_enums()`. 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. Smile, Juliette 1: https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/6fbbc1078094d905f0773421f13830744a144d1e/autoload.php#L153-L247 2: https://www.php.net/manual/en/function.get-declared-classes.php#refsect1-function.get-declared-classes-changelog --------------090301050005050109060607 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 17-8-2024 2:00, Mike Schinkel wrote:
To everyone on this thread and thus nobody in specific (hence my top post):

Given that get_declared_*() populates a new ZEND_HASH each time the function is called[1] — which for classes can easily be hundreds of strings — would there be any appetite to: 

1. Add an optional parameter — e.g. `get_declared_classes($startingFrom)` — that can limit the number of symbols starting with "n"  where if n==100 then it would return array_slice($symbols,100), and 

2. Add a function — `get_declared_class_count()` — that returns the current number of declared symbols of whichever kind of symbol, so we can get the "n" before calling `include`/`require` to use with get_declared_*() after calling  `include`/`require`?


This would cut down on creating hashes with 100+ strings that get immediately thrown away, and also cut down on memory fragmentation/garbage collector churn. 

-Mike

[1] https://github.com/php/php-src/blob/18d41502da0da1bb3928e60c41f1b821974c2c01/Zend/zend_builtin_functions.c#L1371


Mike,

While your suggestion does not directly relate to what triggered my mail to the list, I very very much like the idea.

It's as if you are reading my mind or rather, reading one of the autoloaders [1] I need to maintain, in which your above outlined proposal should definitely make for more efficiency.

Having said that, the same parameter + extra function would then also be needed for `get_declared_interfaces()`, `get_declared_traits()` - and, if it would be added, `get_declared_enums()`.

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.

Smile,
Juliette

1: https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/6fbbc1078094d905f0773421f13830744a144d1e/autoload.php#L153-L247
2: https://www.php.net/manual/en/function.get-declared-classes.php#refsect1-function.get-declared-classes-changelog
--------------090301050005050109060607--