Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
On 18 September 2015 01:49:35 BST, John Bafford wrote: >an important benefit to providing a value for enums would be to allow for >changing or deprecating enums. So you might want to say something like: > >enum FormEvents { > PRE_SUBMIT, > PRE_BIND = PRE_SUBMIT, //deprecated name, pr

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
On 18 September 2015 18:31:55 BST, Lester Caine wrote: >On 18/09/15 00:06, Rowan Collins wrote: >> So, what are anyone's thoughts? Am I rambling on too much as usual? >;) > >What happens when you need to switch language? Yes, the names of enum members should be considered labels, not descriptions

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
On 18 September 2015 15:42:44 BST, Anthony Ferrara wrote: >As far as enums, I wonder if they would be necessary if we supported >algebraic types, since you could define an "enum" as a virtual type: > >const MONDAY = 0; >const TUESDAY = 1; >const WEDNESDAY = 2; >const THURSDAY = 3; >const FRIDAY =

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
On 18 September 2015 08:05:11 BST, "Pavel Kouřil" wrote: >personally, I feel that you should be able to assign numeric value to >each element (and have them implicit if not specified). > >This is imho better for serialization (but it can be done with names >as well, yeah) - but more importantly, i

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Jefferson Gonzalez
On 09/18/2015 02:29 PM, Rowan Collins wrote: Jefferson Gonzalez wrote on 18/09/2015 19:25: 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. It already mentions that: > Enu

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
Jefferson Gonzalez wrote on 18/09/2015 19:25: 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. It already mentions that: > Enums are strongly typed and can be used as param

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Jefferson Gonzalez
On 09/18/2015 01:21 PM, Levi Morrison wrote: On Fri, Sep 18, 2015 at 11:18 AM, Rowan Collins 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 n

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Lester Caine
On 18/09/15 00:06, Rowan Collins wrote: > So, what are anyone's thoughts? Am I rambling on too much as usual? ;) What happens when you need to switch language? This is one area where a well formatted database system fills many holes. Simply selecting a subset of entries from a table allows a user

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Levi Morrison
On Fri, Sep 18, 2015 at 11:18 AM, Rowan Collins 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

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
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 b

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Levi Morrison
(CC'ing internals as it was apparently dropped by Jeff) On Fri, Sep 18, 2015 at 11:03 AM, Levi Morrison wrote: > On Fri, Sep 18, 2015 at 9:59 AM, Jefferson Gonzalez wrote: >> On 09/18/2015 10:21 AM, Levi Morrison wrote: >>> >>> On Fri, Sep 18, 2015 at 1:05 AM, Pavel Kouřil wrote: On F

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Jefferson Gonzalez
On 09/18/2015 10:21 AM, Levi Morrison wrote: On Fri, Sep 18, 2015 at 1:05 AM, Pavel Kouřil wrote: On Fri, Sep 18, 2015 at 1:06 AM, Rowan Collins wrote: Hi All, This has come up in passing a few times recently, but I'm not sure there's ever been a dedicated discussion of it: would it be usefu

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Jefferson Gonzalez
On 09/18/2015 10:42 AM, Anthony Ferrara wrote: As far as enums, I wonder if they would be necessary if we supported algebraic types, since you could define an "enum" as a virtual type: const MONDAY = 0; const TUESDAY = 1; const WEDNESDAY = 2; const THURSDAY = 3; const FRIDAY = 4; use MONDAY | TU

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
Bob Weinand wrote on 18/09/2015 15:23: Well, I think we should*either* have an ordinal*or* a name. But not both. Currently, after thinking about it, I'm in favor of just a name. And no ordinal. Having both is, I think, unnecessary. Yeah, that was my instinct. It's a bit like surrogate keys o

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Anthony Ferrara
Levi et al, On Fri, Sep 18, 2015 at 10:11 AM, Levi Morrison wrote: > On Thu, Sep 17, 2015 at 5:52 PM, John Bafford wrote: >> On Sep 17, 2015, at 19:16, Bob Weinand wrote: >>> Am 18.09.2015 um 01:06 schrieb Rowan Collins : This has come up in passing a few times recently, but I'm

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Bob Weinand
> Am 18.09.2015 um 10:42 schrieb Rowan Collins : > > On 18 September 2015 01:15:43 BST, Bob Weinand wrote: >> The reason it is not an associative array is that the names are not >> important. > ... >> You never should *rely* on the ordinal value of the enum for anything. > > I feel like I'm miss

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Levi Morrison
On Fri, Sep 18, 2015 at 1:05 AM, Pavel Kouřil wrote: > On Fri, Sep 18, 2015 at 1:06 AM, Rowan Collins > wrote: >> Hi All, >> >> This has come up in passing a few times recently, but I'm not sure there's >> ever been a dedicated discussion of it: would it be useful for PHP to have a >> built-in E

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Levi Morrison
On Thu, Sep 17, 2015 at 5:52 PM, John Bafford wrote: > On Sep 17, 2015, at 19:16, Bob Weinand wrote: >> >>> Am 18.09.2015 um 01:06 schrieb Rowan Collins : >>> >>> This has come up in passing a few times recently, but I'm not sure there's >>> ever been a dedicated discussion of it: would it be us

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Rowan Collins
On 18 September 2015 01:15:43 BST, Bob Weinand wrote: >The reason it is not an associative array is that the names are not >important. ... >You never should *rely* on the ordinal value of the enum for anything. I feel like I'm missing something here. In my mind, the only absolute universal about

Re: [PHP-DEV] Let's discuss enums!

2015-09-18 Thread Pavel Kouřil
On Fri, Sep 18, 2015 at 1:06 AM, Rowan Collins wrote: > Hi All, > > This has come up in passing a few times recently, but I'm not sure there's > ever been a dedicated discussion of it: would it be useful for PHP to have a > built-in Enumeration type, and if so, how should it look? > > Many other l

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Ben Scholzen
On 18.09.2015 01:06, Rowan Collins wrote: Hi All, This has come up in passing a few times recently, but I'm not sure there's ever been a dedicated discussion of it: would it be useful for PHP to have a built-in Enumeration type, and if so, how should it look? For what it's worth, there's SplEn

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread John Bafford
> On Sep 17, 2015, at 20:15, Bob Weinand wrote: > >> Am 18.09.2015 um 01:56 schrieb Rowan Collins : >> >> 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

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Bob Weinand
> Am 18.09.2015 um 02:35 schrieb John Bafford : > >> On Sep 17, 2015, at 20:06, Bob Weinand wrote: >> >>> Am 18.09.2015 um 01:52 schrieb John Bafford : >>> >>> If we’re bikeshedding, one feature I would really like to see, with >>> typehinting, is warnings if all cases of an enum aren’t handle

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Bob Weinand
> Am 18.09.2015 um 02:27 schrieb Ryan Pallas : > > I few questions wrt the rfc: https://wiki.php.net/rfc/enum > >> An enum value is only equal to itself. > I'm not sure I agree. How then do I store the enum into a DB and compare it > after reading? > switch($db->query('select role from user where

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread John Bafford
> On Sep 17, 2015, at 20:06, Bob Weinand wrote: > >> Am 18.09.2015 um 01:52 schrieb John Bafford : >> >> If we’re bikeshedding, one feature I would really like to see, with >> typehinting, is warnings if all cases of an enum aren’t handled in a switch. >> So, for example, given our example We

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Ryan Pallas
I few questions wrt the rfc: https://wiki.php.net/rfc/enum > An enum value is only equal to itself. I'm not sure I agree. How then do I store the enum into a DB and compare it after reading? switch($db->query('select role from user where user_id = 123')->fetch()[0]) { case UserRole::Admin:

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Bob Weinand
> Am 18.09.2015 um 01:56 schrieb Rowan Collins : > > 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

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Bob Weinand
> Am 18.09.2015 um 01:52 schrieb John Bafford : > > On Sep 17, 2015, at 19:16, Bob Weinand wrote: >> >>> Am 18.09.2015 um 01:06 schrieb Rowan Collins : >>> >>> This has come up in passing a few times recently, but I'm not sure there's >>> ever been a dedicated discussion of it: would it be use

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Rowan Collins
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 th

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread John Bafford
On Sep 17, 2015, at 19:16, Bob Weinand wrote: > >> Am 18.09.2015 um 01:06 schrieb Rowan Collins : >> >> This has come up in passing a few times recently, but I'm not sure there's >> ever been a dedicated discussion of it: would it be useful for PHP to have a >> built-in Enumeration type, and i

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Marcio Almada
Hi, 2015-09-17 20:06 GMT-03:00 Rowan Collins : > Hi All, > > This has come up in passing a few times recently, but I'm not sure there's > ever been a dedicated discussion of it: would it be useful for PHP to have a > built-in Enumeration type, and if so, how should it look? > > Many other language

Re: [PHP-DEV] Let's discuss enums!

2015-09-17 Thread Bob Weinand
> Am 18.09.2015 um 01:06 schrieb Rowan Collins : > > Hi All, > > This has come up in passing a few times recently, but I'm not sure there's > ever been a dedicated discussion of it: would it be useful for PHP to have a > built-in Enumeration type, and if so, how should it look? > > Many other

[PHP-DEV] Let's discuss enums!

2015-09-17 Thread Rowan Collins
Hi All, This has come up in passing a few times recently, but I'm not sure there's ever been a dedicated discussion of it: would it be useful for PHP to have a built-in Enumeration type, and if so, how should it look? Many other languages have enum types, with varying functionality. The cent