Re: [RFC] Enumerations
| From: | Pierre R. | Date: | Mon, 07 Dec 2020 15:35:28 +0000 |
| Subject: | Re: [RFC] Enumerations | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112457@lists.php.net to get a copy of this message | ||
Le 07/12/2020 à 16:26, Larry Garfield a écrit :
On Mon, Dec 7, 2020, at 2:46 AM, Michał Marcin Brzuchalski wrote: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, PierreThanks for taking the topic. I love it. Regarding theWe 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,::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