Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112456 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54762 invoked from network); 7 Dec 2020 15:58:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2020 15:58:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 38C7D1804DD for ; Mon, 7 Dec 2020 07:26:59 -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 out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (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 ; Mon, 7 Dec 2020 07:26:58 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0232E5C01B9 for ; Mon, 7 Dec 2020 10:26:58 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Mon, 07 Dec 2020 10:26:58 -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=gEc7e9iJt7p2owkUZJsaOYFmYP4uxEWmQtnHIyG/2 SU=; b=kqqdpTn7nSKLpLtmy8b1c0oHS3wm7BCVSdWAwBUAY8dWi0xOHW3ETPUCO G/YH8MSzy3ewPDzYqInJJt6RIgVnKkltgZ310DOvqttlbawgvXHrrwsSelYF3dJm JUds/6ZqLinEv1bsKzRdrswwkK65x05kx/p2HJaDi/EyjCRoeyYwIVOTVWgSbQJw c71DYO2OCNXGQ4O2IWfvSUL9/a1MyVTRgtuS3RQdIkHW72e6Nq0p/ZO8rAHvcjXo py+/n/fV5uIE0w8CSqHIAq49X9m0ds+ph3xH4UuaM8k9ZqZF8v7WSZzbOqBhdSBq XyUrOQ2S6U2W0qJY9slHlYdm66jcg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejgedgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepffffffejffdugfegvedviedttedvgfejffefffej leefjeetveehgefhhfdvgfelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 79FAF14200A2; Mon, 7 Dec 2020 10:26:57 -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: <244f66fb-81c3-4cf7-a0b5-0a3233e3b9e1@www.fastmail.com> In-Reply-To: References: Date: Mon, 07 Dec 2020 09:26:36 -0600 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Enumerations From: larry@garfieldtech.com ("Larry Garfield") On Mon, Dec 7, 2020, at 2:46 AM, Micha=C5=82 Marcin Brzuchalski wrote: > Hi Larry, >=20 > Thanks for taking the topic. I love it. >=20 > Regarding the `::cases()` method on UnitEnum I guess it'd be more natu= ral > to cast enum into an array like: >=20 > (array) Suit; >=20 > but I realize it'd be harder to implement. The question is if it was e= ven > considered? >=20 > Regarding the `::from()` method responsible for casting was a natural = cast > operator considered instead? > For eg. > $suit =3D (Suit) $record['suit']; > Instead of: > $suit =3D Suit::from($record['suit']); >=20 > Cheers, > Micha=C5=82 Marcin Brzuchalski We didn't really get into explicit casting, since it's so rarely used in= conventional PHP code these days. I'm not sure off hand if supporting = (Suit)"H" or (string)Suit::Hearts would be easy or hard. That would be = an Ilija question. Assuming it's feasible to do, what do people feel about supporting that?= IMO, cases(), from(), and values() need to be kept no matter what as t= hey're more self documenting and can be passed around as callables. So = the question is just whether we should also try to add casting as an ali= as to those operations. --Larry Garfield