Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112700 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2052 invoked from network); 31 Dec 2020 17:41:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Dec 2020 17:41:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B59E5180384 for ; Thu, 31 Dec 2020 09:16:04 -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.1 required=5.0 tests=BAYES_00,BODY_8BITS, 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 out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 ; Thu, 31 Dec 2020 09:16:04 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BBA605C01B3 for ; Thu, 31 Dec 2020 12:16:02 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Thu, 31 Dec 2020 12:16:02 -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=jV2/hjnZZizWkseCC1rYzbNXDZIbtPOWn4uWhrfWh m0=; b=T6/cMoPxXXOHYyeF79uWvpr1Jh6lDSkBxp5QU8w1RlP6GGZiaALIksFPS tMhGqglZltZbc8g50z8GonW+1tVcZPzC+b2A6OKeaAD3CRtZKGWw5Z9GAUWRn9Dc C8Km5twBT9ZE2EC2umzfdjiQwHrsccbAnHV3EKc/lZvz1Yu6SDKBp/yLIDFiM83F HhgoCUvci1uD14Z4NMNqRvzl/oJPAXy1biGiuPaaTWn40JrOBhuWQ0sVkHnlW6++ D4vUDyPcjSBWUiePmXoP6XuA9jCba5xA0YWHUxPLT73+YgzUfJ9hdZ068sykFKvf valRryV39xJNCjp9e9CO8KS7ST+XQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvhedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1312D14200A2; Thu, 31 Dec 2020 12:16:02 -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: <7d8ce2a2-8d85-4312-af22-da643faa3a7f@www.fastmail.com> In-Reply-To: <4eec7448-f7ab-9955-8c2d-68cd4f822535@gmail.com> References: <8aa05350-05fc-df9d-e5d6-fa0f4feb57ba@alec.pl> <4eec7448-f7ab-9955-8c2d-68cd4f822535@gmail.com> Date: Thu, 31 Dec 2020 11:15:41 -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 Thu, Dec 31, 2020, at 6:53 AM, Rowan Tommins wrote: > On 30/12/2020 21:24, Aleksander Machniak wrote: > > My argument is that, from an end-user perspective, I don't really se= e > > why Unit and Scalar enums have to have different "API" at this point= . > > I'm talking about ":string"/":int" in the enum definiton as well as > > ->value and ->from(). >=20 >=20 > My personal opinion is that for many enums, explicitly not having a=20= > scalar representation is a good thing. >=20 > This is basically similar to my opinion of __toString() etc: if you ha= ve=20 > *multiple* ways to convert something to/from a scalar, blessing one of= =20 > them as "default" is arbitrary and confusing. >=20 > For example: >=20 > enum BookingStatus { > =C2=A0=C2=A0=C2=A0=C2=A0 case PENDING; > =C2=A0=C2=A0=C2=A0=C2=A0 case CONFIRMED; > =C2=A0=C2=A0=C2=A0=C2=A0 case CANCELLED; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0 public function getId() { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return m= atch($this) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::PENDING =3D> 1, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CONFIRMED =3D> 2, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CANCELLED =3D> 3, > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; > =C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0 public function getCode() { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return m= atch($this) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::PENDING =3D> 'PEN', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CONFIRMED =3D> 'CON', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CANCELLED =3D> 'CAN', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; > =C2=A0=C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0=C2=A0 public function getEnglishDescription() { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return m= atch($this) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::PENDING =3D> 'Pending Payment', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CONFIRMED =3D> 'Confirmed', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 self::CANCELLED =3D> 'Cancelled', > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; > =C2=A0=C2=A0=C2=A0=C2=A0 } > } That is similar to our reasoning. It creates a foot-gun situation where= someone could get in the habit of assuming that an enum always has a *r= easonable* and *logical* and thus *reliable* string equivalent, when not= all enums will have string equivalents that it's reasonable and logical= to use. So, one less foot gun. Also, one of the extensions planned, as noted, is ADTs/tagged unions. T= hose could not have a primitive equivalent, since they're not singletons= . Keeping UnitEnum and ScalarEnum separate allows us to later add Tagge= dEnum (or similar) that also extends UnitEnum, but not ScalarEnum. --Larry Garfield