Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124970 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 2CBAA1A00B7 for ; Fri, 16 Aug 2024 05:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723787993; bh=CI3eZBSYgiwo0WWpdpEnq9hzqO7BUBECcFo2WlyWc8M=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=MvVYzrZDJek3o+x6cfU8BlYghhULYGpYwTpor8ytvaJL7LaSKeUoaGhvSShxta7xD QGABZ/y4yaRuPE5vNrkdlmkwJBaPXUYFa9WviFmSatFiNBlVyKLFquGxHK/Yl9lvvd A5up9LBfD/watmDbDarzEqXXwjkBkpuxxW3Jo1WUK76PQtv9BKJ8BKhYjUmip1T7ZH uNseBHpQdONVshkoX1W8XWyA5oVl6fWIX+RpEW2eTD5+lNgiJ9HylEc2Vxyhza4558 xKuO+hvI3VmUWAS6EoaKt8aNf7bZQ3jQuT6gHVqV5cXdU7MfkN/e4Lko2yWyJJ5Uhw DVePegroexXtw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C3FE618004A for ; Fri, 16 Aug 2024 05:59:52 +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.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (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 ; Fri, 16 Aug 2024 05:59:52 +0000 (UTC) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e0e76380433so1722438276.2 for ; Thu, 15 Aug 2024 22:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1723787884; x=1724392684; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LBHpa71AYR5ny+k9Y5lCxZY6xtLlq2dKxbhAdUNvrAQ=; b=bHZ6JFDa+T/udlzhXxPwuhI3JUpSqDx0PqUHylLlKVDbSZa3nBpqCVNvHMNaEZxkaj YNgnYi7FI7xHFaoQnCjFK1XWBndNZMyfpOlZZ0Viq/DLE29lB9Gd+6qhbi4FbZml3Evx +ixJ65+6xd6suJjmIdY6QnTDCjDKxNEC2FVQQsYgphDulrT7TX5XrFHpq1M85+wKaNcm jjXzDBVjBu31dxWXxxwxFkX2HKmP1ZleT5H35Dnd35/itPE/Aw4jCAflrM7yU80BBHxS Y/s5lY47ngsEW9qLVWtNaKGwdve+O5oPTISsWLBSNcJiqfH811TC7MDTuhhWvHKRpeZn 22jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723787884; x=1724392684; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LBHpa71AYR5ny+k9Y5lCxZY6xtLlq2dKxbhAdUNvrAQ=; b=K7vQ8kacjG1eKro1O4PjvfObBI3syE4xTlGUXX190EVWjDpvb7w91e/6D4meYEVu+C bhHILnX9iL5mc0/mOZ6CiRC+a3PWrYyHJsxC8bZkyumaBgrtrnhh2nRjyRbrnyzBPP5F 7AzjJmx6zABebpdZUQSocccUFojTRzEga1bWf8ta3enWswKiB913B2IWHaFXkUed9NCX lrCRe2LZZob1PUKBlJ5axVrhCoIKkGa0BymV3Z6SGaf+ydDhOJeC+xk+ZQEa2Gs0zKuY 8p2F8koPxnyWZUbJUdeg2RrOziUZSbVhKL1BUGxIa0bT70F2Yn+uvmqjDY5eftleeVqB Y6lw== X-Gm-Message-State: AOJu0Yx2LfQvEibADK0M67PS714IJQF3jdozMOZh6I3onOYrys+6mrIx whYauZ4EiYaKwHCxK8IpQHkCcDDWRFNfr/zrdY8nmMVZ3Ro6XtUTV6q44ap+mbQ= X-Google-Smtp-Source: AGHT+IHxlL5bfVgKVyVT18KAt1/658e75dq5nbyYhEC5pnRRFBKph3NlykiPPbbnmkvuaFBjacdmXg== X-Received: by 2002:a05:6902:260d:b0:e0e:c82a:f188 with SMTP id 3f1490d57ef6-e1180f1492dmr2193060276.30.1723787884384; Thu, 15 Aug 2024 22:58:04 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e1171e68e4dsm630944276.27.2024.08.15.22.58.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Aug 2024 22:58:03 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] Should there be a `get_declared_enums()` function ? In-Reply-To: <87fc9033-b0cc-423a-bcb6-8cef287a8ee6@app.fastmail.com> Date: Fri, 16 Aug 2024 01:58:02 -0400 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <657540B3-489C-46B8-B326-1958707AFBDE@newclarity.net> References: <66BD5F05.8010409@adviesenzo.nl> <87fc9033-b0cc-423a-bcb6-8cef287a8ee6@app.fastmail.com> To: Larry Garfield X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Wed, Aug 14, 2024, at 8:51 PM, Juliette Reinders Folmer wrote: > Should a `get_declared_enums()` function be added ? My answer is "very much, yes." > On Aug 15, 2024, at 9:09 AM, Larry Garfield = wrote: > Context: I can't remember the last time I used get_declared_classes() = (...it's a kinda pointless function) Your experience is one data point. Another data point is my experience = that it is fortunate that `get_declared_classes()` exists as I find it = to be a very a useful function. The core library I use for most projects = depends on it for class initialization.=20 Your comment made me curious to see if others use it, and there are 8.1k = uses on GitHub:=20 - = https://github.com/search?q=3Dlanguage%3Aphp+get_declared_classes&type=3Dc= ode Here is how I have used, in a greatly simplified example: function autoload($class) { $classCount =3D count(get_declared_classes()); if (!file_exists("src/{$class}.php")) { return; } include_once "src/{$class}.php"; foreach (get_declared_classes() as $class) { if (!method_exists($class,'init')) { continue; } $class::init(); } } As an aside, for this use-case I have always wanted PHP to add both 1.) = a `get_declared_class_count()` function and 2) optional parameters for = `get_declared_classes()` that would allow requesting a subset of = classes, such as just the newly added classes. How important this is = depends on if PHP maintains that array internally and just returns a = reference, or if it instantiates memory and populates the array of = classes to return every time the function is called. > , so when we were working on enums it never occurred to us to think = about it. It wasn't a deliberate decision to omit, as far as I recall. >=20 > I think I'd be open to adding it; my concern would be the overlap with = get_declared_classes(), which as you note currently would include enums, = and changing that is a BC break (even if a tiny one that I doubt would = impact anyone). Add another parameter =E2=80=94 or include as part of the args array =E2=80= =94 something like this (though I am sure this could be bikeshed to be = better): get_declared_classes(DeclaredClasses:ONLY_CLASSES, = ['starting_from'=3D>174]); get_declared_classes(DeclaredClasses:ALL, ['recently_declared'=3D>3]); Or even: DeclaredSymbols::get_classes([$args]) <-- returns only classes, not = enums DeclaredSymbols::get_enums([$args]) DeclaredSymbols::get_interfaces([$args]) DeclaredSymbols::get_traits([$args]) #fwiw > On Aug 16, 2024, at 12:23 AM, Juliette Reinders Folmer = wrote: > Thanks for the response. It was exactly a (custom) autoloader = situation which caused me to start wondering about this. Seems Juliette's use-case may be at least somewhat similar to mine. -Mike=