Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113042 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11179 invoked from network); 1 Feb 2021 19:47:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Feb 2021 19:47:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A3E3B1804CF for ; Mon, 1 Feb 2021 11:30:06 -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=-1.2 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 11:30:05 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6CB7B5C01C5 for ; Mon, 1 Feb 2021 14:30:04 -0500 (EST) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Mon, 01 Feb 2021 14:30:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=YA7OwQoTsbhDqXKIJknljb8ykVccDT88y4ojzcO1Y +Q=; b=TDGNHrFt57KnLU7Mcg7SgsMMqrUoQ9bu/zArKmaSplqvtMedDmcYCGys+ 8sW/1yeLR0uQknTe1giW/6w2wDFw/Xsva+raDVg3oPMOmNtDz/ew3tOZuXdcXnvo S1iXG3ZcTgO6Oa+9c7piaqVOVvN+larVSUwxExEZIMGLVbRpCshuduPJAd6vdyVA yXWnVAQ+0rguttxAnvfl3kHBJHvTSpVP55HWHZNI9DshsVs0J/gfn/Mxal7fryvc nKFJs2iqm2AHwhYpDXYgrYRXxTipoL/XAWkDmHQpgR0060KG/L4kgau4pGdasEV8 je3B01dnk/aPdRtoM8SNQC5/SwplQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeekgdduvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepteeutdduveffkeehgeelteeljedtleeuhfekuddu gffffeduieetfffgveeggeegnecuffhomhgrihhnpehphhhprdhnvghtpdhorhgrtghlvg drtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 084B43A0074; Mon, 1 Feb 2021 14:30:04 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-84-gfc141fe8b8-fm-20210125.001-gfc141fe8 Mime-Version: 1.0 Message-ID: <3261e170-636c-4645-b42f-4c14c2d9c5eb@www.fastmail.com> In-Reply-To: References: Date: Mon, 01 Feb 2021 13:29:42 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: [RFC] Enumerations, Round 2 From: larry@garfieldtech.com ("Larry Garfield") 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 vot= e. > > Baring any major issues being brought up, we plan to start the vote = in the > > first half of next week, probably Tuesday-ish. If you have any othe= r bug > > reports or tweaks, please speak now or forever hold your patches. > > > > --Larry Garfield > > > > > Hi, >=20 > Maybe IterableEnum can actually be just Enum. As you are not allowed t= o > 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 forg= et > 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 bein= g called `Enum`, even internally. > Also in the interface I think you can include the name property, simil= arly > with how you did in BackedEnum interface. > https://wiki.php.net/rfc/property_accessors will probably allow it to = be > clearly defined at some point. >=20 > 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 functi= on > 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 i= t sometimes being ->value(), sometimes ->legacyValue(), sometimes ->asIn= t(), 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 E= num, > 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 p= roperty. 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