Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112680 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96096 invoked from network); 30 Dec 2020 20:11:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Dec 2020 20:11:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 849A31804F4 for ; Wed, 30 Dec 2020 11:46:13 -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 wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.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 ; Wed, 30 Dec 2020 11:46:12 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 08110AFB for ; Wed, 30 Dec 2020 14:46:11 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Wed, 30 Dec 2020 14:46:12 -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=ENU5VEz7YIj7CJf7nUGfWGQRavGsHED1y0mtYuNpT 3E=; b=UtOrbBMiUhVHrl0er08136e82RIAC2pMjSJC6NRedNSbOk0qlUb7jJBJN 9Ym/YlbP3P1DnI5L69F2zYYN4yipnhsxgtHKRLZWhNWP6TNJ4MkFMyoOZhfR/xrn DeeXnOY2kSY2kcugPOAvbP0SOKb/1h0d27f+AuAhISvNxQASkni9N5rdnDR+zZo3 bj8rm65CmtWGvI2DZk7KsumziFVJAxnDSSkzPiZE7VRFycbdGh7BUNGwz9yYmzJy jE12ha4DVNY1WrPPNDmu1eDcsRGgTJOjP/zQyudC/BGCZV3a65NGPJ17lIYGXTaD s/Nk4xIV5jWV3Hqd2iurbLiO8NnPQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvfedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeeggeehgfetjeehgefggefhleeugefgtdejieev vdethfevgeeuudefleehvdetieenucffohhmrghinhepphhhphdrnhgvthenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 31FEA14200A2; Wed, 30 Dec 2020 14:46:11 -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: <7f4049fc-18a9-47ae-87ff-ef2a24009df3@www.fastmail.com> In-Reply-To: References: Date: Wed, 30 Dec 2020 13:45:50 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: larry@garfieldtech.com ("Larry Garfield") On Wed, Dec 30, 2020, at 4:12 AM, Alexandru P=C4=83tr=C4=83nescu wrote: > Nice evolution overall. >=20 > Few notes: > - I think ScalarEnum::fromValue() would be more clear than just from()= and > more in sync with ->value property. Any name would work, I suppose. I prefer short, single-word methods whe= re possible, myself. > - For the class structure you gave an example to illustrate the 'simil= ar' > way it is related to class, it would be nice to also mark the class as= > final. It would. Added. > - I agree with no state behavior, at least at this point. However, I w= ould > have liked to offer the ability for very easy creation of > singleton/multiton patterns using enums, like in Java. I'm not sure what you're describing here. Do you mean tagged unions/ADT= s, which are punted to a later RFC? =20 https://wiki.php.net/rfc/tagged_unions > - Enums evolve in time and cases are added or sometimes removed. When = the > storage of the case stays externally (as scalar values or serialized),= > there could be issues when some of them are removed in the meantime. Possibly; though that's no different than a class evolving or going away= in time. Either way it's up to the developer to figure out what BC str= ategy makes sense. > - for ScalarEnum::from(), for missing values I would guess we will t= hrow > an exception, maybe a specific one? Can we mention it in the RFC? It already says a ValueError is thrown. It probably does make sense to = subclass that, though. I'll mention it to Ilija. > - for deserialization, how should it be handled? using an exception = as > well, same exception as in the previous case. Ilija and I discussed this a bit, and settled on an invalid deserialiati= on issuing a warning and returning false. An exception would probably b= e better, but right now deserialize() doesn't throw things so introducin= g that just for enums seems inconsistent. He'll be updating the impleme= ntation shortly. > - The allowed_classes option on unserialize() method, I'm guessing it = will > work with Enums just like every other class, putting an instance of > __PHP_Incomplete_Class? Enums don't have unsafe behavior in their constructors the way classes d= o, so we're not convinced there's a reason to exclude them. For now all= owed_classes does not include enums. > - Inheritance would work between enums. But only by eliminating some c= ases. > I can see how enum RedSuites could extend enum Suites without breaking= LSP. > Not sure if it makes sense to dig on this now. >=20 > Regards, > Alex Possibly as a future scope, if we see demand for it. The RFC is ambitio= us enough as is and already has several follow-ups planned for more adva= nced cases. :-) Cheers! --Larry Garfield