Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113044 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22454 invoked from network); 1 Feb 2021 20:46:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2021 20:46:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E93571804D0 for ; Mon, 1 Feb 2021 12:29:50 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 1 Feb 2021 12:29:50 -0800 (PST) Received: by mail-ot1-f50.google.com with SMTP id d7so17655109otf.3 for ; Mon, 01 Feb 2021 12:29:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6g1YdN3VGtr+9abC7ABRcr0Y8MyUMZGtm7bXkWeFCG8=; b=f/l3NtaI75mnmoZiny3S/D6yKP8ybhewSJVhnFfdm9kqOAPlld6245WSUxmMUq9itx ezTIUmVB1fWsBeOmcMCHAr3lhAZW2wtuPfFHC6U1ff+8J/CgAOSFUPetN0bMcLgRkDSS qpu4RZuBS2hCoC5vSXjuCz9GAntlLy5HEhwImFqmyvgarnreqWMlMKTjHR/utv/fBTs1 b8w1WIDaZP02DglA/KIen2aa0GzUol0q/HxhYzqVBYldx2u+DI0aG2cHimnMcs0KiWjB G2ZIP0qpZCXBBywSRxU66b1ovOkgDz9HAe55E7uZPO3VwuugwhFkdtGtnuwCrBzxU7Ot /AdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6g1YdN3VGtr+9abC7ABRcr0Y8MyUMZGtm7bXkWeFCG8=; b=bLr51PJGb63I9MCvo8BbLfTm1BWlN0Nj0QQXPdbvcSMxFF7v1BBmQK3aK/fm4Uv425 Z+jhpoWs544NoIzxRGoLEDh/2OZ4sQp82sdWqnx1VPRTRedZqngvC7EU+1Blw3cdXLu8 tSwlB4fI9X6MJ4I0xvb97VpAhAtKfjyMFcITlJThUjDSqsFg8Fz1QxkPyq4rZkgTkT0F XZ2p3UVv2j1F056Z34EDQC3u+xzo6A4/wRRPwzr5UtSHkUlCSNy77zOPyn9/4TXlW9Ny A6vLmZv/+85BHRfg7J/QXZ9ecv9vlcGlkfnXwWQnLOE/cXUCVQ+c5UAunG+G+J2UC3Be J+Nw== X-Gm-Message-State: AOAM530KMjW6C6doYKjpD4Z7AEGFqvKEek93/WQmWsvsN/X6vcQf/mwY GXNJAOeSpk+JYq1KOb4wdOXdW59yuizYQxjmmVmOn2LokaW2/g== X-Google-Smtp-Source: ABdhPJxuFKavN/5A6xp5Cqz3DzE/g67sy8DJOSB3KN8W2KMAfZoLFMk45kE39Tiwdtc/nLXJjPWqsj4XiJPVK/nMd04= X-Received: by 2002:a9d:7503:: with SMTP id r3mr4591660otk.236.1612211389255; Mon, 01 Feb 2021 12:29:49 -0800 (PST) MIME-Version: 1.0 References: <3261e170-636c-4645-b42f-4c14c2d9c5eb@www.fastmail.com> In-Reply-To: <3261e170-636c-4645-b42f-4c14c2d9c5eb@www.fastmail.com> Date: Mon, 1 Feb 2021 20:29:38 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000028d20a05ba4c37f2" Subject: Re: [PHP-DEV] Re: [RFC] Enumerations, Round 2 From: davidgebler@gmail.com (David Gebler) --00000000000028d20a05ba4c37f2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > We tried that. The `enum` keyword precludes any class or interface being called `Enum`, even internally. Enumerable, Enumerated, Enumerator? On Mon, Feb 1, 2021 at 7:30 PM Larry Garfield wrote: > On Mon, Feb 1, 2021, at 11:48 AM, Alexandru P=C4=83tr=C4=83nescu wrote: > > > > > https://wiki.php.net/rfc/enumerations > > > > > > At this point, Ilija and I consider the RFC done and ready for a vote= . > > > Baring any major issues being brought up, we plan to start the vote i= n > the > > > first half of next week, probably Tuesday-ish. If you have any other > bug > > > reports or tweaks, please speak now or forever hold your patches. > > > > > > --Larry Garfield > > > > > > > > Hi, > > > > Maybe IterableEnum can actually be just Enum. As you are not allowed to > > implement it and/or define it, wouldn't it work? That's how it's named > > internally in Java, not that it would matter but sometimes people forge= t > > it's just syntactic sugar there as well ( > > https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html): public > > abstract class Enum> implements Comparable, > > Serializable. > > We tried that. The `enum` keyword precludes any class or interface being > called `Enum`, even internally. > > > Also in the interface I think you can include the name property, > similarly > > with how you did in BackedEnum interface. > > https://wiki.php.net/rfc/property_accessors will probably allow it to b= e > > clearly defined at some point. > > > > A bit it bothers me that backed enums are very easy to implement even > > without the special case and just a simple Enum would be fine. > > I mean even if you will have a backed enum, with would be simple and > > probably the need will come at some point to have also a public functio= n > > getLegacyValue(): string and a public static function > > fromLegacyValue(string $value): Enum. > > But yes, using backed values is a common pattern so I'm guessing it's a > > valuable important use case. > > It's more about standardizing the API. An ORM can rely on a backed enum > always exposing its "value to save to the DB" at ->value, rather than it > sometimes being ->value(), sometimes ->legacyValue(), sometimes ->asInt()= , > etc. > > > For storing in a database purpose, property name can be used directly, = I > > think. > > It would nice to have in the rfc the recommended way to retrieve the > Enum, > > given that you know the name. > > I'm guessing that would be Suit::$name; > > That doesn't work for referencing a constant; it gets read as a static > property. That's a more general syntactic question for PHP, and one we'r= e > not going to solve here. :-) Really, ->name is more an implementation > artifact. If you want to have a primitive to pass around, for whatever > reason, that's what a backed enum is for. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000028d20a05ba4c37f2--