Re: Let's discuss enums!

From: Date: Fri, 18 Sep 2015 18:25:14 +0000
Subject: Re: Let's discuss enums!
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-88348@lists.php.net to get a copy of this message
On 09/18/2015 01:21 PM, Levi Morrison wrote:
On Fri, Sep 18, 2015 at 11:18 AM, Rowan Collins <rowan.collins@gmail.com> wrote:
Levi Morrison wrote on 18/09/2015 18:04:
Anything else is trying to add value in some way – in your case you are adding a primitive value that the language will automatically map for you. I'm not saying that is a bad thing but I hope you can at least recognize that it is an addition and not the bare minimum. The RFC I am planning on proposing will have only the bare minimum because it's the least controversial part and is the most useful. The other stuff we can debate about later.
That's why I was kind of surprised to see ordinal() in there in the draft - it's an additional field on each member, which in many cases has no relationship to the value being represented.
I suspect it will be removed before hitting the official discussion phase :D
Also, apologies for accidentally starting the discussion of your draft "too early", I wasn't aware that you were working on it. I was trying to offer something productive to the language, since I've been spending a lot of time talking down new features lately. :)
No worries – it happens.
I also believe the rfc should include type hinting of enums as has been mentioned on this discussion. That would make enumerations more useful and the rfc more complete. enum Weekday {SUNDAY=0, MONDAY=1, TUESDAY=2, WEDNESDAY=3} function set_day(Weekday $day) : Weekday {
    // $day can only be numbers 0,1,2,3
    //$return can only also be 0,1,2,3
} Enums is a really needed feature for PHP that would have make code much more cleaner and easy to follow than what we have today.

« previous php.internals (#88348) next »