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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php