Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Pierre R.
Le 05/12/2020 à 00:24, Larry Garfield a écrit : Greetings, denizens of Internals! Ilija Tovilo and I have been working for the last few months on adding support for enumerations and algebraic data types to PHP. This is a not-small task, so we've broken it up into several stages. The first st

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Pierre R.
Le 05/12/2020 à 00:24, Larry Garfield a écrit : Greetings, denizens of Internals! Ilija Tovilo and I have been working for the last few months on adding support for enumerations and algebraic data types to PHP. This is a not-small task, so we've broken it up into several stages. The first st

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Markus Fischer
Hi, On 05.12.20 10:22, Pierre R. wrote: I think that ::cases() should always return an array/iterable without keys, and let userland write their own code to create hashmaps with those when they need it. I think that having one case (non primitive cases) that doesn't yield string keys and the o

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Pierre R.
Le 05/12/2020 à 12:14, Markus Fischer a écrit : Hi, On 05.12.20 10:22, Pierre R. wrote: I think that ::cases() should always return an array/iterable without keys, and let userland write their own code to create hashmaps with those when they need it. I think that having one case (non primiti

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Marc Bennewitz
Am 05.12.20, 00:25 schrieb "Larry Garfield" : Greetings, denizens of Internals! Ilija Tovilo and I have been working for the last few months on adding support for enumerations and algebraic data types to PHP. This is a not-small task, so we've broken it up into several stages. The f

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Larry Garfield
On Sat, Dec 5, 2020, at 3:26 AM, Pierre R. wrote: > Le 05/12/2020 à 00:24, Larry Garfield a écrit : > > Greetings, denizens of Internals! > > > > Ilija Tovilo and I have been working for the last few months on adding > > support for enumerations and algebraic data types to PHP. This is a > > not

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Pierre R.
Le 05/12/2020 à 15:42, Larry Garfield a écrit : On Sat, Dec 5, 2020, at 3:26 AM, Pierre R. wrote: Another question, about match() behavior: > This usage requires no modification of |match|. It is a natural implication of the current functionality. May be this could be the time to have a "s

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Larry Garfield
On Sat, Dec 5, 2020, at 8:21 AM, Marc Bennewitz wrote: > *dons flame-retardant suit* > > Hi Larry, > > thanks for your great initiative and hard work in this! > I'm the author of an emulated enumeration lib [1] and really looking > forward seeing native enumeration support in PHP. > > Here

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Rowan Tommins
(Apologies if this posts twice, I may have accidentally hit send before I'd finished writing it) On 05/12/2020 14:21, Marc Bennewitz wrote: * Do cases have a stable ordinal number / position and is that accessible? This would be very interesting on implementing an optimized EnumSet using b

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Rowan Tommins
On 05/12/2020 15:08, Larry Garfield wrote: * Are cases serializable? `Suit::Spades === unserialize(serialize(Suit::Spades)) // true` Right now they'd do the same as objects, so they'd serialize as an object. Unserializing like that, though... hm, that would probably NOT still be === due to

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread tyson andre
Hi Larry Garfield, > Right now they'd do the same as objects, so they'd serialize as an object. > Unserializing like that, though... hm, that would probably NOT still be === > due to the way PHP handles objects. > That's probably undesireable, but I'm not sure at the moment the best way > around

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Marc Bennewitz
Am 05.12.20, 16:08 schrieb "Larry Garfield" : On Sat, Dec 5, 2020, at 8:21 AM, Marc Bennewitz wrote: > > * How can you access a defined case value? > Something like `Suit::Spades->value()` At the moment it's only accessible via the ::cases() method. It may be appropr

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Marc Bennewitz
Am 05.12.20, 16:21 schrieb "Rowan Tommins" : (Apologies if this posts twice, I may have accidentally hit send before I'd finished writing it) On 05/12/2020 14:21, Marc Bennewitz wrote: > * Do cases have a stable ordinal number / position and is that accessible? >This

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Rowan Tommins
On 05/12/2020 19:21, Marc Bennewitz wrote: I mean on mapping something to something else defined as a single assoc array constant. Something like: enum Role { case User, case Admin, ... } enum Action { case Order_Edit, case Order_Read, private const BY_ROLE = [ Role

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Larry Garfield
On Sat, Dec 5, 2020, at 1:21 PM, Marc Bennewitz wrote: > > * I often use metadata in enumerations and so I would be very > > interested to allow constants. > > > Could you give an example what you mean? Metadata on individual cases is > supported by methods, which map more clea

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Larry Garfield
On Fri, Dec 4, 2020, at 5:24 PM, Larry Garfield wrote: > Greetings, denizens of Internals! > > Ilija Tovilo and I have been working for the last few months on adding > support for enumerations and algebraic data types to PHP. This is a > not-small task, so we've broken it up into several stages

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Benjamin Morel
Thanks a lot for this RFC, Larry and Iliya! I can't imagine the amount of thought and work put into this. Enums are definitely a most-wanted PHP feature. I played a bit with the early implementation, and love it so far. Here are my thoughts on the RFC and the current implementation: *Serializatio

Re: [PHP-DEV] [RFC] Enumerations

2020-12-05 Thread Paul Crovella
On Fri, Dec 4, 2020 at 7:00 PM Larry Garfield wrote: > > > Dec 4, 2020 7:37:51 PM Paul Crovella : > > > On Fri, Dec 4, 2020 at 3:25 PM Larry Garfield > > wrote: > >> > >> Greetings, denizens of Internals! > >> > >> Ilija Tovilo and I have been working for the last few months on adding > >> supp