Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112636 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23363 invoked from network); 29 Dec 2020 16:07:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Dec 2020 16:07:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AB2861804C4 for ; Tue, 29 Dec 2020 07:42:26 -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.6 required=5.0 tests=BAYES_00,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 out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 29 Dec 2020 07:42:26 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5AFFA5C0118 for ; Tue, 29 Dec 2020 10:42:26 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Tue, 29 Dec 2020 10:42:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=jn6s5F e0NhsqZy+iK+qS8owfo+qCE+NHey/JHMkgtik=; b=qWij4aIXwmLMQcr7lTdT7g 5i2tBfHeHeDM0HAk5s5HKHfxIYnRGEs8fNQq9UswkqWs7EYSd1GDNEB00bhq0AJO sq/McZbIBlhN/+iV4Y4uSYFZGNZB9HdcRLarMQnOWQJyd87+h0OS4JURzfO97vVM hHvvSdmJriRQBY58YbYZ+QDdW0nSpAySF/6XIO4tmML7rBrw/MD/TPdnT2RlG2Sj NHiMx6/12olf+MotTJ69Fwv+nlBQCi61qkPDpdvqGwilGGGI9K2yJn6o2D7uMlGe F6oo0fjn5f1eAZKBuH5jehsaV9KGEvOESQv0kNZDti0YY7BIWFClMWSLovWSd0JA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvuddgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id E8B8414200A2; Tue, 29 Dec 2020 10:42:25 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-ID: <5120eee2-56c4-4608-9e41-4dd05563fef7@www.fastmail.com> In-Reply-To: <67c9d05a-f0a7-fcea-32ea-7a4e409308a1@mabe.berlin> References: <67c9d05a-f0a7-fcea-32ea-7a4e409308a1@mabe.berlin> Date: Tue, 29 Dec 2020 09:42:04 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: larry@garfieldtech.com ("Larry Garfield") On Tue, Dec 29, 2020, at 2:48 AM, Marc wrote: > > On 28.12.20 21:21, Larry Garfield wrote: > > Hello, Internalians! > > > > After considerable discussion and effort, Ilija and I are ready to offer you round 2 on enumerations. This is in the spirit of the previous discussion, but based on that discussion a great deal has been reworked. The main change is that Enumeration Cases are now object instances of the Enumeration class rather than their own class. Most of the other changes are knock-on effects of that. > > > > Of particular note: > > > > * Cases may not have methods or constants on them. They're just dumb values. > > * Enums themselves may have methods, static methods, or constants. > > * Traits are supported, as long as they don't have properties. > > * The value() method on scalar enums is now a property. > > > > The full RFC is here, and I recommend reading it again in full given how much was updated. > > I did and the RFC looks really awesome :+1: > > I don't have time to test the implementation but I noticed one thing: > > > If the enumeration is not a Scalar Enum, the array will be packed > (indexed sequentially starting from 0). If the enumeration is a Scalar > Enum, the keys will be the corresponding scalar for each enumeration. > > I don't think using the scalar values as keys is a good idea. What > happens if we want to support scalar float values? (Why are they > actually not supported in the first place?) That's why floats are not supported, in fact, because what happens to them when they are made into an array key is non-obvious. (PHP would say to convert to a string, but that's always fussy with possible data loss in some cases, etc.) We decided to just avoid that problem until/unless someone found a good use case for float enums. No all languages support them as is, so there is precedent. > Also I think it's more natural if both enum types return a > zero-indexed-array of cases. The goal is to make it easy to work with them, and having a clean lookup map readily available is very convenient. If you don't care about the scalar equivalent then you can safely ignore them. If you do want them, then you have a lookup table ready-made for you. That's the logic we were working from. --Larry Garfield