On Wed, Dec 30, 2020, at 12:30 PM, Aleksander Machniak wrote:
> On 28.12.2020 21:21, Larry Garfield wrote:
> > https://wiki.php.net/rfc/enumerations
> Why can't this be simplified to:
> 
> enum Size {
>   case Small;
>   case Medium;
>   case Large;
> }
> 
> 'Small' === Size::Small->value; // true
> Size::from('Small') === Size::Small; // true
> 
> enum Suit {
>   case Hearts = 'H';
>   case Diamonds = 'D';
>   case Clubs = 'C';
>   case Spades = 'S';
> }
> 
> 'H' === Suit::Hearts->value; // true
> 'Hearts' === Suit::Hearts->value; // false

That's a possibility we've been kicking around.  I'm considering it, Ilija 
doesn't care for it. :-)  What's your argument in favor?

Related: There is an internal "case" value that is used as well.  It could be 
exposed as a normal read-only property, which would always be equal to the name 
of the case ("Hearts"), regardless of whether another "value" is defined.  
We're still undecided on that, too.

> Also, how about using a method instead of property for ->value?

We originally did.  Ilija preferred moving it to a property since there will 
need to be one anyway to store the value.  I moderately favor a method but 
don't greatly care either way.

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to