Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113045 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32923 invoked from network); 1 Feb 2021 21:15:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2021 21:15:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AB1EF1804CF for ; Mon, 1 Feb 2021 12:58:47 -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-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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:58:47 -0800 (PST) Received: by mail-ej1-f42.google.com with SMTP id l9so26582101ejx.3 for ; Mon, 01 Feb 2021 12:58:47 -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=WAZYHl1lW9ThB9tD6kcyC3jpPzTikYobsUt2ioEHr90=; b=DFH1wvzQ1zW+/hTuegV4aE6zyQcsAF//q7jR4iTZx58q6z2Ro33MlyDFupZXgWujEW fQbDiRJ88nemQ/7L7OsocHfMxiB6lnsM2kXwm7FWaitt5GihT+ktPtcJyW61i58rij4r YrEDtxt4xvhIhX/e1cRCBq+hNMpGyAWEibNReIfoKOTFwCZh4gu/8oTLH9wPKgp6YjCG 51hoxUf7pFtlj4eMcdcvhDQob6ERsbCOU5PfwOWlk4iH4YyESTBI19+qGnOdd9TzZhHp 3dLOsvsjWU15OnognrIUMeb4RVsVIpd4Gb+3FP5SOY7Jrzu6FWJ6m3iuDGQ8iq+ti78R dvWQ== 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=WAZYHl1lW9ThB9tD6kcyC3jpPzTikYobsUt2ioEHr90=; b=hV6ydZVeANh7TpU85C1jXJvaxNgZ6LcbGkJtCDoTGyBeWDdgvW5nIluJgYaBVVQcod ukZ3UBL8JSTJ/H+YannOB7Ld0Ge9HE0hyFfoIdjRAoHzE1RNcChzCw6K3T9S6gDeL6Q+ 2qv0u5DmxBbpG+WgnrIQ/RcF14nWrvCcct42Gg0i8tXLsS9p4wNj/DtjAUPeNagtFEik DakymUX+OWuOPaqD1DgdvkEKxALDI1+xS0z4PQzT5PjG7pg6gU2bv/twNQObm+acLtPQ N9uEz/uiG+D8fokEtWyRf3enSWni7HQOmwITSy6mgO4W2EzYGhf8t5HyXJF07m6Pw8tg DdhQ== X-Gm-Message-State: AOAM530vlhdm9sHqVQA6EStj5KoGxTSXbCdVO5ntIvDKW2Zjatn21Pg5 yjlS3hG7yKboyRWawPK2Z6hK4W+0f6NlFxFEUk5Qdite89ZigDrr X-Google-Smtp-Source: ABdhPJz46SaY9U61Dr8yajpxNy7NnyMW3upx0lk6Q3EThWY0KOeaEB5o84sgF35UXMKeGsHUDGg/ND58KeI/uBIynJE= X-Received: by 2002:a17:906:15ca:: with SMTP id l10mr19139340ejd.402.1612213121218; Mon, 01 Feb 2021 12:58:41 -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 22:58:22 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000647dd005ba4c9e93" Subject: Re: [PHP-DEV] Re: [RFC] Enumerations, Round 2 From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000647dd005ba4c9e93 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 1, 2021 at 9: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. > > I see. I made an assumption based on how I thought the situation should be. Maybe that should not be impossible but I'm a bit further from understanding how that could be fixed. > 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. > > Yes, you are right. It would work however with constant(Suit::class . '::' . $name) so someone could very easily define a static method for that and serialization for a database is back for not backed enums. Maybe there would be a way to remove the name public property completely to avoid missusages? So a "pure enum" should only be used in code as property, parameter, return value types, reading from the constant and compared with identity operator (match included). Whenever that enum needs to be stored as a value as user defined int/string, a backed enum should be used that has a public read-only value property and a public static from method. Yes... sounds good. Alex --000000000000647dd005ba4c9e93--