Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125028 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 4C2D71A00BD for ; Sat, 17 Aug 2024 17:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723916024; bh=wsVgSYnjUVa8xDkMKwXngwRKSV9XzvrJh2HZCJG5ci8=; h=From:Subject:Date:References:To:In-Reply-To:From; b=MwxC8KUSDFwZuEN8hDLW7GoScQXXupsaCmvP7j8Rkl/tVfLG+rMd/wEZif3mLSFVU F+P155bQXsSR6HeDJh2TBL1swIG06ssYrOVVxHYpsxl/tqIB234XScp3WG0syjCgGu 5lXfAH0Kf1PZyp1DqjI+KXD9bf9Rz1U98mDYVy1nBgPhpLtDGY4V02ECsFuHEGBeGy Bf6S1MkE/sIpRharJxN7diP6qTwyKoK1m1UBD8RYfo3e6bVi9muSdpg/G58e8l1g/s SPvsLI+cMfkLdCjMgqpk79rqrjPSiUMWp8XH3lTu3i+Dxgh2YyIWxd1BTDnCsdJWwh gGo1krkIUMkMw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0F4EB18005C for ; Sat, 17 Aug 2024 17:33:44 +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_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 17:33:43 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3717ff2358eso1581004f8f.1 for ; Sat, 17 Aug 2024 10:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723915914; x=1724520714; darn=lists.php.net; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=xSKYtH7AV+g1s9Z/LcZMyh0qe8D0x3FpPbRSkarSsuA=; b=mRD2e2mcCiYroKT9WFgMk586LZYn6Ke2E6+vUN20VegU1qortvrihDZB3pX9R+muNj IPdxnSPh3tDsR5dClTROJBmx2NqXKXngBrLfDeJjhXjeWcOMNQwFRdz6Fl6QlUpE6QOf npPF+s56jzm5rqyM+JogWBJcM8KX0XqrA6xcFm3bjbQtAxi+h55ePAYAd1uACo0BUAbS HsVz0EiqmCqg7oXVutP2aOJqgQM2xJa492bUez0nRfGVaHEQAXFKQAoEdgGz9WizlqN1 3QXxfJ0EHUyG1fVkdrQbG7HpWbfTun5hvm4BsLdO2WXhnCRw8Z4gUPHJLFDaKvsAvZsU 2x6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723915914; x=1724520714; h=message-id:in-reply-to:to:references:date:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xSKYtH7AV+g1s9Z/LcZMyh0qe8D0x3FpPbRSkarSsuA=; b=P/m7SJDdK+lU4Rtlt5lFm2WfzRxQi9b6W+54U6r2uKi8xr41Pa56lKF2sNSScFKe+y sqPkQ/gN8dNscR+D4y/VLKWmFlEja/r2PP+lyk4fzq20566P9eW9ZqWYW4dyx5CAdBsO CPFqkvW5DDDOEREbNkj0wFySg9oxCi33mQETrxf6BNM8tH3yHru/enWPWou2Dze4SbyI J583FUgwcATZKBM1yu8T+SEbwVUxqLZdzYJwrpcbwoTO640DnlQ/H9bP5S9TZ8zjInE6 pa0ZhCSHimeGr+M3GS7in+dUlhShTOk8UJzL4SmJi6E97Toh7gNQhCjlpWI3zdAfq/Z+ 4RXQ== X-Gm-Message-State: AOJu0Yz1SA+w6CgGUK2mARrW7jO9oLHUHrw2HrV3BTCIHWr7udjMaU1H WoPjjbGuQuiuIDARsInhu0UdlmnRgC74MDUAcM9I8kU0rgsfkkgjkYogkQ== X-Google-Smtp-Source: AGHT+IFBKEM8TaMMpVXLwZa55dBpjWfkxAqm5l8od/uy4WNio3trOBtvbDre685SfG0AGQUwct/U/g== X-Received: by 2002:adf:cf09:0:b0:367:96a8:d94b with SMTP id ffacd0b85a97d-371946cbc00mr3540354f8f.57.1723915913870; Sat, 17 Aug 2024 10:31:53 -0700 (PDT) Received: from smtpclient.apple ([178.197.214.118]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-371898b89bdsm6260138f8f.112.2024.08.17.10.31.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Aug 2024 10:31:53 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 \(3776.700.51\)) Subject: Re: [PHP-DEV] Should there be a `get_declared_enums()` function ? Date: Sat, 17 Aug 2024 19:31:40 +0200 References: <66BD5F05.8010409@adviesenzo.nl> <8dc51539-20bb-4017-b859-76066e2287e5@gmx.de> <66BFF486.3020707@adviesenzo.nl> To: php internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3776.700.51) From: claude.pache@gmail.com (Claude Pache) > Le 17 ao=C3=BBt 2024 =C3=A0 15:17, Larry Garfield = a =C3=A9crit : >=20 > On Fri, Aug 16, 2024, at 7:53 PM, Juliette Reinders Folmer wrote: >> On 16-8-2024 17:01, Ayesh Karunaratne wrote: >>> I went ahead and created PR = https://github.com/php/php-src/pull/15443 along with tests, UPGRADE = notice, etc. I think having a `get_declared_enums` function will be = helpful. The implementation is simple and straightforward too. >> Thanks for creating the PR Ayesh! >>=20 >> I'm presuming it's too late for PHP 8.4, what with feature freeze=20 >> having come & gone this week. >>=20 >> Based on the mostly supportive responses on the list, I wonder = whether=20 >> an RFC is needed. If so, I'd be happy to create an initial draft (for=20= >> PHP 8.5). >>=20 >> Smile, >> Juliette >=20 > I would prefer to have an RFC for this, even if it's short. I'm not = against it, I just think there's enough non-trivial questions (eg, = impact on get_declared_classes()) that it warrants an RFC = process/discussion. >=20 > --Larry Garfield Hi, I concur with Larry, it should not be rushed into PHP 8.4, but carefully = considered if it is really the correct function to define. Enums were = introduced three years ago, and until three days ago, there has been = apparently no complaint of the missing function, and it has been = proposed less because of a need than because of an apparent lack of = symmetry with other `get_declared_*()` functions. So, there is no = urgency. Now, the proposed design for `get_declared_enums()` is problematic, = because it will bring (or sustain) confusion. An enum is (imo = rightfully) considered as a class for the purpose of = `class_exists(...)`; and following the same logic, the proposed = `get_declared_enums()` returns (rightfully) a subset of the names = returned by `get_declared_classes()`. On the other hand, in the mind of = many people =E2=80=93 as it can be seen in several messages in this = thread, and citing the original poster =E2=80=93, there are four = different OO structures in PHP: classes, interfaces, traits, and enums. = For example, one is tempted to write na=C3=AFvely: ```php function get_declared_symbols(): array { return [ ...get_declared_classes(), ...get_declared_interfaces(), = ...get_declared_traits(), ...get_declared_enums() ]; } ``` not realising that enums will appear twice in the returned list. An alternative design that is less confusing could be the following. I = am not really proposing it (as I am personally not convinced that = `get_declared_classes()` filtered by `enum_exists()` is not sufficient), = but I merely give it as an illustrative example of an api thought to = avoid or reduce confusion. We could add an optional parameter to the = existing `get_declared_classes()` function, specifying what sort of = classes they are interested in: ```php const SIMPLE_CLASS =3D 1; const ABSTRACT_CLASS =3D 2; const ANONYMOUS_CLASS =3D 4; const ENUM =3D 8; function get_declared_classes(int $type =3D SIMPLE_CLASS | = ABSTRACT_CLASS | ANONYMOUS_CLASS | ENUM): array { /* ... */ } ``` =E2=80=94Claude