Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125730 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 D16891A00BD for ; Wed, 2 Oct 2024 12:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1727872195; bh=Vlqj8cYxEM8wITdxZ0CWIuphQS/LTG9G3YjBjmJD32g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VnoZsugd2P1L1M/pXDhELZJ0wirdmE0NacP2oc2cQ0WXg7gXMRFz1iOh5WuW51d1e 9IQ2he/TX+/eEdp2wNoFz4TDpKFrQs8q00amLMMrgWWmwVeKtO7ZIyz/FVTQjxP+Wh kN4duoyR6/FbBjgwEJ7ppM622fSeAnglsGJ9W4NtfdY4ZDojRzLFe9SnYIEvBDs//H hj4V7GPfCo21FDr0BDYXQtoJYsKmbyuSmSL7TZ7mW0C16wo6SIB57aX5VU/aHibs6z EAE86qvVEdUu3GCZl7jlRI4ubjXcFhqMg0sKlPtQGtLHC4m3XXQ9d4dMMHftAPg7zS eaem8RRSjHoNw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20EE2180079 for ; Wed, 2 Oct 2024 12:29:54 +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, HTML_MESSAGE,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-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 12:29:53 +0000 (UTC) Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-e260850140fso5024488276.2 for ; Wed, 02 Oct 2024 05:27:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727872059; x=1728476859; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=I8doEvt9Zm4bKmMGjioHrWVwtB4lhX218/iLtayYGFg=; b=nO1+FtmPfUA1rH65yuNlKIIsLDz3qJJv/GTWNnERa3ZjK+Vrj/8YLoj6FN+i2Rxt8m jg26YBnphD28/F6q2QPffWRAkuPNnRp6kSTqGrSZ7E33AVkAbOBFtCx40gqamCXc5xy6 EwgH2FDEaZATQtQ2OBzAcwGP8mCwRFau/TgWjafy1V1NzqwKzRjL7/jPlX+w3Jk0ajr5 gWhRJ7dJ+X7F7VAIqS3n6m3SKVZz2hfNzWsR1GZToGUZ+HD++z3y5vMnOrVpEWiRaHqG j+Sebd4QKRsnMDOOF+ZL7Jh+dWamdk76zf1crk1PtK7gYsZixDnKiykEcL2h7QMnNAzE sgjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727872059; x=1728476859; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=I8doEvt9Zm4bKmMGjioHrWVwtB4lhX218/iLtayYGFg=; b=hCZzo3sT9MeylA3hroN5Zjl9/PQpvs6rXffEo3JT7P01hpknfwfEwy2Kn2XwlVjE36 zCaa88lnTdyISB/P+pACGMKbMgQbW9DMBxo4sBCSEP18VQNi9V1V+woe61/lThDHjxpt HyXrB0Kpb3ZcQkRT1zdUnRsd9qeICzWwB4JHVYkXZLtfx0o1yMQTSrzzZ28jSmEW13ZX r/oYpuhvhf+acuTSiXxJRGkq/KbKjm6ywsch9XCYhXlCEKU12GK77bKJO29SgT+bFbhI c9qxCThU0SeLIr8xoSmw2kxSmJHfBBUEzqlads4x8JJVAz7djo+AUn9RT5juoBmQeAT0 R2tA== X-Forwarded-Encrypted: i=1; AJvYcCW7mzBwR3CdSRuPfFkSu0JeDnD7t53WAiVq6teLFGGwcoWXGjGdTn0c3BY5SKddnwI96bXsJA7i8ms=@lists.php.net X-Gm-Message-State: AOJu0YztLo2QvayQU3acY0d2lE7lDs+2CWh2CCt9D21yyN4adnCO0Nlc nD3pxDOIeJoFea3+ttqSy3hsOy1XufQAgZw513HfxyN297+W4RnJkox1/n86x0UqZpNZYswPQm0 yndRXO0JeCuvFE4RNb9ACUMjMn21ux1C6 X-Google-Smtp-Source: AGHT+IFDBNskw7OMFBARSVNO9l/3gXLmuMkrlyrEBRro51Ytr3H2Mp8J4YoZw725aQDQxrMoie5SMloOjuPm8a3z2i4= X-Received: by 2002:a05:6902:1ac5:b0:e25:d46e:9c03 with SMTP id 3f1490d57ef6-e26383bb1e6mr2304777276.15.1727872059536; Wed, 02 Oct 2024 05:27:39 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <66FC7B9F.5070906@adviesenzo.nl> In-Reply-To: Date: Wed, 2 Oct 2024 15:27:22 +0300 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Add get_declared_enums() function To: Rob Landers Cc: Juliette Reinders Folmer , PHP internals , Ayesh Karunaratne Content-Type: multipart/alternative; boundary="00000000000053800706237d90ff" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --00000000000053800706237d90ff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 2, 2024 at 11:06=E2=80=AFAM Rob Landers wro= te: > 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: > > L.S., > > After the earlier discussion [1] regarding this topic in August, it is ou= r > pleasure to present the RFC to add a `get_declared_enums()` function to P= HP > for discussion. > > https://wiki.php.net/rfc/get_declared_enums > > We look forward to your feedback and hope for a constructive 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. > 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. > I would find it surprising if `get_declared_classes()` would not return > enums. > > 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()); > } > ``` > > -- > Alex > > > 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 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 interfaces (ie, Stringable), you cannot extend anothe= r > class, you cannot instantiate them with =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 be worth implementing a > get_declared_objects() that behaves like get_declared_classes() currently > does. > > =E2=80=94 Rob > Yes, that's a good point as well. I think my view comes from when I initially dug (15+ years ago) into what an enum in Java is, and learned that it is just a syntactic sugar, and a final class would be generated implementing `Comparable` and extending an abstract class `Enum`. And I think in PHP that could be a similar view. And most of the limitations we have are not impossible to create with a standard class. I think in time we might get to remove some limitations. I, personally, don't agree with the `Stringable` related limitation. And also with the limitation on no state. In Java this is the simple way to create a singleton: an enum with one case; and we can't have this in PHP. If we remove the limitations, should we reclassify at that point enums as classes? --=20 Alex --00000000000053800706237d90ff Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Wed, Oct 2, 2024 at 11:06=E2=80=AFAM R= ob Landers <rob@bottled.codes> wrote:
On Wed, Oct 2, 2024, at 09:20, Alexandru P=C4=83tr=C4=83nescu wrote= :

On Wed, Oct 2, 2= 024 at 1:48=E2=80=AFAM Juliette Reinders Folmer <php-internals_nospam@advie= senzo.nl> wrote:
L.S.,

After= the earlier discussion [1] regarding this topic in August, it is our pleasure to present the RFC to add a `get_declared_enums()` function to PHP for discussion.

http= s://wiki.php.net/rfc/get_declared_enums

We look forward to you= r feedback and hope for a constructive 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=C2=A0you 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.
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 ar= e just a specific type of class, final ones.
I would find it = surprising if `get_declared_classes()` would not return enums.

Avoiding a BC break would be nice also if there is no reas= on for it.
One would be able to get only the enums by using s= omething like:
```php
function get_declare= d_enums_only() {
=C2=A0 =C2=A0 return array_diff(get_declared= _classes(), get_declared_enums());
}
```

--=C2=A0
Alex

=

Interesting observation= =C2=A0Alexandru,

I find it weird that class_ex= ists("MyEnum") would return true, but there is only one symbol ta= ble=E2=80=94you can=E2=80=99t name a class and enum with the same name, so = it makes some sense. However, while enums have =E2=80=9Csome=E2=80=9D simil= arities with classes in PHP, they are not the same. For example, you cannot= implement arbitrary interfaces (ie, Stringable), you cannot extend another= class, you cannot instantiate them with =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 thes= e rules in PHP, so I don=E2=80=99t think enums quack sufficiently like clas= ses to be called a class. I would argue that it is an object, however. I th= ink it would be worth implementing a get_declared_objects() that behaves li= ke get_declared_classes() currently does.=C2=A0

=E2=80=94 Rob

Yes, that's a good point as well.

I think my view comes from when I initially dug (15= + years ago) into what an enum in Java is, and learned that it is just a sy= ntactic sugar, and a final class would be generated implementing `Comparabl= e` and extending an abstract class `Enum`.

And= I think in PHP that could be a similar view. And most of the limitations w= e have are not impossible to create with a standard class.

I think in time we might get to remove some limitations.
I, personally, don't agree with the `Stringable` related limitation.
And also with the limitation on no state. In Java this is the simp= le way to create a singleton: an enum with one case; and we can't have = this in PHP.

If we remove the limitations, should = we reclassify=C2=A0at that point enums as classes?

--=C2=A0
Alex
=C2=A0
--00000000000053800706237d90ff--