Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112442 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26233 invoked from network); 6 Dec 2020 16:04:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Dec 2020 16:04:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B4361804C5 for ; Sun, 6 Dec 2020 07:33:09 -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_H4,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 wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (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 ; Sun, 6 Dec 2020 07:33:08 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id ACAE9984 for ; Sun, 6 Dec 2020 10:33:06 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Sun, 06 Dec 2020 10:33:06 -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=vA6SxO AvCTHrpEodZlnVeMuTadeQpQafXOHDC+ZfCos=; b=i6wy2063WNfbgezqNM9LPk EfvI20fSKSbExCUiKs7EufyS+XN2AJThQiLUO6kkhiQzNAQcawz1TUOf/yWHLDu2 uF6ySehE3a4TXGeqJcOLgU0+jeWgx37mgzjQIadMhKz1+Ja7r8rRKACcxpkcXQIW Ek68FJhvheLcSyT9cP8bxRHOgqYtON6hJz3B8GHgDrJGY5aKrEjNIcKUcV5SJ468 Wd5GepsORiuKqFqwWfxl87eRTrREYv5iJI2FVT9dbXZ53XdPn67Nc+Id/pZ41Bvo lFD70ojuVuH9HX1ii6EuSY+tGwu+GJ6/R9dnow5d5XFjZlgqCIxei57+RATQmRIQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejvddgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeekteelheffgeefvddufeeujeekhfdvtdeuuedvveet ieevheeludegjeduhffhteenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgr rhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id C309814200A2; Sun, 6 Dec 2020 10:33:05 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-622-g4a97c0b-fm-20201115.001-g4a97c0b3 Mime-Version: 1.0 Message-ID: In-Reply-To: References: <79044037-4cd4-4065-a3c1-39a4deea3e09@www.fastmail.com> Date: Sun, 06 Dec 2020 09:32:43 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Enumerations From: larry@garfieldtech.com ("Larry Garfield") On Sat, Dec 5, 2020, at 5:23 PM, Benjamin Morel wrote: > Thanks a lot for this RFC, Larry and Iliya! I can't imagine the amount of > thought and work put into this. > Enums are definitely a most-wanted PHP feature. > > I played a bit with the early implementation, and love it so far. Here are > my thoughts on the RFC and the current implementation: Yay! > *Serialization* > > I guess what it comes down to is whether / how easily a class can return > > an existing instance when asked to unserialize, rather than setting > > properties on an existing instance. That is, given the string > > "C:4:Suit:6:{Spades}" can the class definition return the appropriate > > singleton for Suits::Spades rather than a newly constructed object? > > > > If this proves tricky to implement, it would probably be better to > > forbid serialization than using the default object format and breaking > > the singleton-ness of the case objects. > > > +1, totally agree with this statement. That's the first thing I tried when > playing with the implementation, and noticed that serialization is not > supported: > > echo unserialize(serialize(Status::Active)); > Notice: unserialize(): Error at offset 0 of 42 bytes > > I would definitely expect strict equality to be maintained on enum cases > even after unserialization! I've opened a task to just block serialization entirely for now. It's probably best to not support it at all than to have half-arsed buggy support, at least for now: https://github.com/Crell/enum-comparison/issues/46 > *var_export()* > > Currently, var_export() returns a __set_state() syntax: > > var_export(Status::Active); > Foo\Bar\Status::Active::__set_state(array( > )) > > I guess this should just return Foo\Bar\Status::Active. Good point. I've opened a task for that: https://github.com/Crell/enum-comparison/issues/47 > *Scalar Enums, ::cases()* > > The implementation does not support these yet, so I haven't had a chance to > play with them. > I share Pierre R.'s concerns, though: > > Does this mean that an enum can't have two cases with the same primitive > > value ? I would very much being able to do so, for example, when you > > change a name and want to keep the legacy for backward compatibility. > > > But I'd understand if you just disallow duplicate scalar values altogether, > this is probably the most sensible solution here. > Another idea that comes to mind is that cases() could return an iterator > instead of an array, having the cases as keys and the scalars as values, > but this would probably come as a surprise and be bad for DX. Off hand, I'm not sure if any languages support duplicate enums. I can see the use case for renaming, but I suspect it's going to just be too complicated to support in practice. I'll make a note in the RFC that they must be unique. > *Enum & UnitEnum interfaces* > > The implementation does not seem to support these yet. Taking the examples > from the RFC: > > Suit::Hearts instanceof Enum; // true => Parse error: syntax error, > unexpected token "enum" > Suit::Hearts instanceof UnitEnum; // true => FALSE Yeah, we only added that to the RFC text an hour or three before you posted; Ilija has to catch up with the new text yet. :-) Please give him some time. --Larry Garfield