Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125725 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 38D001A00BD for ; Wed, 2 Oct 2024 08:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727856537; bh=GqkIpaB3Z/cl8cWGZXVTdaKGisy+QCU/+gqV5sNpKfc=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=G0BOCoJtIlpAl2K0lYAInHi8/haYEn3fZk49k0d1L10VuyffOBuOVz0m6GEtK2ii0 hRy9LJIddYT1o7ReNxTV/dElpH49COHVnd42ki0VzlyMvCzcO6M7DtOP8qpWG4aez4 N1BpDNqtUXAQ3ecOuu4rVMEPlVti4Zsr/r+43L6FB5wzmGi8cJegWYHj27PlwtwBEg Q0yX8hiXUvEbtdINQxDccDTew0cis2YZwwA92jEXkF0sYLi76UbfT4jw8xVNdLeep1 OIbQApMoLdivmt2fm5DhvAbziBZNna8Wk7VNYKlPB56n/dxC00EZAyIAZGsxNcNGvZ HeRM48Xy4zIwA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4AB4180041 for ; Wed, 2 Oct 2024 08:08:55 +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 fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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 ; Wed, 2 Oct 2024 08:08:55 +0000 (UTC) Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id BA658114015A; Wed, 2 Oct 2024 04:06:41 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-01.internal (MEProxy); Wed, 02 Oct 2024 04:06:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=1727856401; x= 1727942801; bh=E4ar9KHEruYBT7S/GifWXa45Nne5mDyYE53C68td7N8=; b=Z 1n3kDSpchUKHu4MEmMG1ouvx9BE4NtGCiPIWB9tOUEHI6qeGqPD6+RQHEmvmTiIR DNu/lonG7aS9Iuuh+8wN7qsXouTUSzDm10zpho+fAdOTHZFsfYD2H+Za1e1WUq4R pvgPuMYbVhr3Pg1cymC7B95u1idgFBk8F79XHyk+cSuMuDyzfywcq5XkiZMPYcUw FPZKAC9KmTQaWjO2XuYuPinKNm8HTp0uGdKyCbwMJ1Bd869ODWvZPoabeBXva66t 0P7fQbkbJ4mKyYP7Kf7wvICXRkl6rmLLSxiJTpQSp+CLu9Of3SSqv/8fv/gwr1Km RO0YkZiJ5Qv1iNkZrNVYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm2; t=1727856401; x=1727942801; bh=E4ar9KHEruYBT7S/GifWXa45Nne5 mDyYE53C68td7N8=; b=In/pSf9w+1NPM1SD+C61OZbF3M2ez+b1wA7UI4040JS5 bOQIhv0lymwSbrWLdUlhH6tdO/XNjoBdudbmgiG7JF1YTEGX6vwdt+VmyqD6iMrh 5ZZZ0Gip6RVfmSEUEWdz/9/xAAZVtcHNrVmOydQahWrmLD1xpOyESK15Q4+Qcv9Z QKAEreNehiYTBa990Q6MRhnmDbN1lcVRZd516iOi3esLc/1CLG8oTrt9H/kfwOPK l+CJg2CIJQheCBS3Gd9Da31PFrZago4TgPbPVfgZGlYwFUIru1yAEjg7j0tqQsFh 8rImUsbDVRr3qz8Uy9W6Hoz7IZ6EvJhUprCo3cGdmg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddukedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefoggffhffvvefkjghfufgtsegrtderreertdej necuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtg houggvsheqnecuggftrfgrthhtvghrnhepffegveevgedtfffgffdvffdtvdehueelgeev keetffeuleeitdegkeejtedtteeknecuffhomhgrihhnpehphhhprdhnvghtnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghothht lhgvugdrtghouggvshdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepphhhphdqihhnthgvrhhnrghlshgpnhhoshhprghmsegrughvihgvshgv nhiiohdrnhhlpdhrtghpthhtohepughrvggrlhgvtghssehgmhgrihhlrdgtohhmpdhrtg hpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvthdprhgtphhtthho pegrhigvshhhsehphhhprdifrghttghh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id F3DB0780069; Wed, 2 Oct 2024 04:06:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Wed, 02 Oct 2024 10:06:20 +0200 To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= , "Juliette Reinders Folmer" Cc: "PHP internals" , "Ayesh Karunaratne" Message-ID: In-Reply-To: References: <66FC7B9F.5070906@adviesenzo.nl> Subject: Re: [PHP-DEV] [RFC] [Discussion] Add get_declared_enums() function Content-Type: multipart/alternative; boundary=6667e731ac1e4c7fbe6f057b53ac3939 From: rob@bottled.codes ("Rob Landers") --6667e731ac1e4c7fbe6f057b53ac3939 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Oct 2, 2024, at 09:20, Alexandru P=C4=83tr=C4=83nescu wrote: >=20 > On Wed, Oct 2, 2024 at 1:48=E2=80=AFAM Juliette Reinders Folmer wrote: >> L.S., >>=20 >> After the earlier discussion [1] regarding this topic in August, it i= s our pleasure to present the RFC to add a `get_declared_enums()` functi= on to PHP for discussion. >>=20 >> https://wiki.php.net/rfc/get_declared_enums >>=20 >> We look forward to your feedback and hope for a constructive discussi= on. >=20 > I'm all for `get_declared_enums()`. > However, I don't accept that enums are not classes and going with the = assumption that they are not will bring more problems than it solves. >=20 > I noticed how you analyzed things internally, that everything is a cla= ss internally, including an interface or a trait. > But this is an API for the userland, and in userland this is not true. > The 3 structures: classes, interfaces and traits and distinct things t= hat you can use in different ways in (generated) code. >=20 > I believe that in userland, the common understanding is that enums are= just a specific type of class, final ones. > I would find it surprising if `get_declared_classes()` would not retur= n enums. >=20 > Avoiding a BC break would be nice also if there is no reason for it. > One would be able to get only the enums by using something like: > ```php > function get_declared_enums_only() { > return array_diff(get_declared_classes(), get_declared_enums()); > } > ``` >=20 > --=20 > Alex >=20 Interesting observation Alexandru, I find it weird that class_exists("MyEnum") would return true, but there= is only one symbol table=E2=80=94you can=E2=80=99t name a class and enu= m with the same name, so it makes some sense. However, while enums have = =E2=80=9Csome=E2=80=9D similarities with classes in PHP, they are not th= e same. For example, you cannot implement arbitrary interfaces (ie, Stri= ngable), you cannot extend another class, you cannot instantiate them wi= th =E2=80=9Cnew=E2=80=9D, you cannot have state, you cannot clone them, = magic methods are forbidden, etc. You cannot build a =E2=80=9Cclass=E2=80=9D with these rules in PHP, so I= don=E2=80=99t think enums quack sufficiently like classes to be called = a class. I would argue that it is an object, however. I think it would b= e worth implementing a get_declared_objects() that behaves like get_decl= ared_classes() currently does.=20 =E2=80=94 Rob --6667e731ac1e4c7fbe6f057b53ac3939 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Oct 2, = 2024, at 09:20, Alexandru P=C4=83tr=C4=83nescu wrote:
=
On Wed, Oct 2, 2024 at 1:48=E2=80=AFAM Juliette Reinders Folmer= <php-internals= _nospam@adviesenzo.nl> wrote:
<= span class=3D"size" style=3D"">L.S.,

After the earlier discussion [1] regarding thi= s topic in August,=0A it is our pleasure to present the RFC to ad= d a=0A `get_declared_enums()` function to PHP for discussion.
=
https://wiki.php.net/rfc/get_declared_enums
<= br> We look forward to your feedback and hope for a constructive=0A = discussion.

I= 'm all for `get_declared_enums()`.
However, I don't accept= that enums are not classes and going with the assumption that they are = not will bring more problems than it solves.

I noticed how you analyzed things internally, that everything is = a class internally, including an interface or a trait.
But= this is an API for the userland, and in userland this is not true.
<= /div>
The 3 structures: classes, interfaces and traits and distinct = things that you can use in different ways in (generated) code.
=

I believe that in userland, the common understanding= is that enums are just a specific type of class, final ones.
<= div>I would find it surprising if `get_declared_classes()` would not ret= urn enums.

Avoiding a BC break would be nic= e also if there is no reason for it.
One would be able to = get only the enums by using something like:
```php
function get_declared_enums_only() {
  &n= bsp; return array_diff(get_declared_classes(), get_declared_enums());
}
```

--&nb= sp;
Alex

=

Interesting observation Alexandru,

I find it weird that class_exists("MyEnum") would retur= n true, but there is only one symbol table=E2=80=94you can=E2=80=99t nam= e a class and enum with the same name, so it makes some sense. However, = while enums have =E2=80=9Csome=E2=80=9D similarities with classes in PHP= , they are not the same. For example, you cannot implement arbitrary int= erfaces (ie, Stringable), you cannot extend another class, you cannot in= stantiate them with =E2=80=9Cnew=E2=80=9D, you cannot have state, you ca= nnot clone them, magic methods are forbidden, etc.

You cannot build a =E2=80=9Cclass=E2=80=9D with these rules in P= HP, so I don=E2=80=99t think enums quack sufficiently like classes to be= called a class. I would argue that it is an object, however. I think it= would be worth implementing a get_declared_objects() that behaves like = get_declared_classes() currently does. 

=E2=80=94 Rob
--6667e731ac1e4c7fbe6f057b53ac3939--