Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112457 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56647 invoked from network); 7 Dec 2020 16:06:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2020 16:06:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CF1B21804CA for ; Mon, 7 Dec 2020 07:35:31 -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=0.4 required=5.0 tests=BAYES_40,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 7 Dec 2020 07:35:31 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id 465515101324; Mon, 7 Dec 2020 15:35:29 +0000 (UTC) To: Larry Garfield , php internals References: <244f66fb-81c3-4cf7-a0b5-0a3233e3b9e1@www.fastmail.com> Message-ID: Date: Mon, 7 Dec 2020 16:35:28 +0100 MIME-Version: 1.0 In-Reply-To: <244f66fb-81c3-4cf7-a0b5-0a3233e3b9e1@www.fastmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] [RFC] Enumerations From: pierre-php@processus.org ("Pierre R.") Le 07/12/2020 à 16:26, Larry Garfield a écrit : > On Mon, Dec 7, 2020, at 2:46 AM, Michał Marcin Brzuchalski wrote: > >> Thanks for taking the topic. I love it. >> >> Regarding the `::cases()` method on UnitEnum I guess it'd be more natural >> to cast enum into an array like: >> >> (array) Suit; >> >> but I realize it'd be harder to implement. The question is if it was even >> considered? >> >> Regarding the `::from()` method responsible for casting was a natural cast >> operator considered instead? >> For eg. >> $suit = (Suit) $record['suit']; >> Instead of: >> $suit = Suit::from($record['suit']); >> >> Cheers, >> Michał 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 they'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 alias to those operations. > > --Larry Garfield > Hello, I deeply hate dark magic, and my motto is always "explicit is better". So I'm NOT in favor of magic/explicit casting neither array-like syntax on enums. If it was only about me, I'd remove array syntax at all in PHP except for real numerical-indexed static arrays in favor of explicit list/hashmap/etc methods, but that's probably my Java past talking here :) Regards, Pierre