Re: Let's discuss enums!

From: Date: Thu, 17 Sep 2015 23:56:47 +0000
Subject: Re: Let's discuss enums!
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-88299@lists.php.net to get a copy of this message
On 18/09/2015 00:16, Marcio Almada wrote:
A kitten is working on thathttps://wiki.php.net/rfc/enum. Many points on the linked RFC are compatible to the points you raised so it might be worth reading before even starting any new proposal.
Aha, I hadn't seen that, should have thought to search the wiki. Still, interesting that we seems to mostly agree on the key decisions, although I've gone into more detail about things that he's left as Future Scope, which is fair enough. The main thing I'd change if I was writing it is the implicit "ordinal" property; I don't really see the point of insisting that the order I write "Red, Green, Blue" has some meaning. On the other hand, I'd give much more prominence to the name, e.g. by making values() return an associative array. You're much more likely to want to say "the value whose name is 'RED'" than "the value I defined first in the list", IMHO. If you have some kind of initialiser syntax for the values - with or without a constructor - you get to have ordinals or explicit values (like the Flags example) if you want them, and just names if not: enum RenewalAction{
    Deny( 0 ),
    Approve( 1 );
    public $ordinal;
} enum Flags{
    a (1  <<  0),
    b( 1  <<  1),
    c(  1  <<  2),
    d(  1  <<  3 ); public $value; }
enum PimaryColours { RED, GREEN, BLUE } Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#88299) next »