Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-02-01 Thread Bob Weinand
> Am 29.01.2021 um 18:15 schrieb Larry Garfield > : > > And we're back again. The RFC has been updated with a steady stream of > smaller improvements based on feedback and testing, and is now in its Final > Form(tm) (we think). The only major change worth noting is that we

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-25 Thread G. P. B.
On Mon, 25 Jan 2021 at 02:29, Larry Garfield wrote: > Aside from some nitpicking around reflection and possibly fiddling with > the naming of "Scalar Enum" et al, we're closing in on the final version. > It will probably go to a vote in the not too distant future. > > --Larry Garfield > > -- >

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-24 Thread Larry Garfield
On Mon, Dec 28, 2020, at 2:21 PM, Larry Garfield wrote: > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to > offer you round 2 on enumerations. This is in the spirit of the > previous discussion, but based on that discussion a great deal has been >

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-06 Thread Nikita Popov
On Tue, Jan 5, 2021 at 6:56 PM Larry Garfield wrote: > On Tue, Jan 5, 2021, at 8:26 AM, Nikita Popov wrote: > > > Nice work, I like the updated proposal. Some notes: > > > > > Similarly, enum names and case names are both case insensitive. > > > > I agree that enum names should be case

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-05 Thread Larry Garfield
On Tue, Jan 5, 2021, at 8:26 AM, Nikita Popov wrote: > Nice work, I like the updated proposal. Some notes: > > > Similarly, enum names and case names are both case insensitive. > > I agree that enum names should be case insensitive (like class names), but > why should case names be case

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-05 Thread Nikita Popov
On Mon, Dec 28, 2020 at 9:22 PM Larry Garfield wrote: > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer > you round 2 on enumerations. This is in the spirit of the previous > discussion, but based on that discussion a great deal has been

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-05 Thread Rowan Tommins
On 04/01/2021 22:04, Mike Schinkel wrote: I don't quit get how you are thinking of with ": string"; can you give an example? The current RFC requires the declaration of a Scalar Enum [1] to include the scalar type, so it looks like this: enum BookingStatus: string {   case PENDING =

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-05 Thread Peter Bowyer
On Mon, 4 Jan 2021 at 15:21, Pierre R. wrote: > I do not agree with having values per default, this is error prone in > most of my use cases. > > In most case where I need enums, I often need to replicate those in > database too, or in message broker serialized messages: in this context, >

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Mike Schinkel
> On Jan 4, 2021, at 9:05 AM, Rowan Tommins wrote: > > On 04/01/2021 11:15, Markus Fischer wrote: >> On 03.01.21 12:01, Mike Schinkel wrote: >>> So in my perfect world this: >>> >>> enum BookingStatus { >>> case PENDING; >>> case CONFIRMED; >>> case CANCELLED; >>> } >>> >>>

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Pierre R.
Le 04/01/2021 à 16:12, Markus Fischer a écrit : I can't say whether just `: string` is too much, but in general I like it. I can follow the reasoning having no value by default and opt this in. The opt-in you suggested is very low-overhead (albeit a bit subtle, but maybe someone has a

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Markus Fischer
On 04.01.21 16:12, Markus Fischer wrote: I can't say whether just `: string` is too much, but in general I like it. Apologies, I meant to write "too magic" :} - Markus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Markus Fischer
Hi, On 04.01.21 15:05, Rowan Tommins wrote: On 04/01/2021 11:15, Markus Fischer wrote: On 03.01.21 12:01, Mike Schinkel wrote: So in my perfect world this: enum BookingStatus {   case PENDING;   case CONFIRMED;   case CANCELLED; } Would be equivalent to: enum BookingStatus {    

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Rowan Tommins
On 04/01/2021 11:15, Markus Fischer wrote: On 03.01.21 12:01, Mike Schinkel wrote: So in my perfect world this: enum BookingStatus {   case PENDING;   case CONFIRMED;   case CANCELLED; } Would be equivalent to: enum BookingStatus {   case PENDING = "PENDING";   case

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-04 Thread Markus Fischer
Hi, On 03.01.21 12:01, Mike Schinkel wrote: So in my perfect world this: enum BookingStatus { case PENDING; case CONFIRMED; case CANCELLED; } Would be equivalent to: enum BookingStatus { case PENDING = "PENDING"; case CONFIRMED = "CONFIRMED"; case

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Larry Garfield
On Sun, Jan 3, 2021, at 2:25 PM, Marc wrote: > >> You already provide a lookup mechanism with `MyEnum::from()` - I don't > >> see a real use-case for proving a pre build map. The main use case I see > >> is to list all possible enum values but this doesn't require a map and a > >>

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Marc
Hi Ilija, On 03.01.21 12:54, Ilija Tovilo wrote: Hi Marc I don't have a really good use-case for float values. It just seems weird to me that a ScalarEnum doesn't support all scalars. Using the enum value as array key for `cases()` works with your current proposal but if we later want to

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Ilija Tovilo
Hi Marc > I don't have a really good use-case for float values. It just seems > weird to me that a ScalarEnum doesn't support all scalars. > > Using the enum value as array key for `cases()` works with your current > proposal but if we later want to allow floats, bool whatever then we got > a

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Marc
On 03.01.21 11:56, Marc wrote: > On 29.12.20 16:42, Larry Garfield wrote: >> On Tue, Dec 29, 2020, at 2:48 AM, Marc wrote: >>> On 28.12.20 21:21, Larry Garfield wrote: Hello, Internalians! After considerable discussion and effort, Ilija and I are ready to offer you round 2 on

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Mike Schinkel
> On Dec 31, 2020, at 12:15 PM, Larry Garfield wrote: > > On Thu, Dec 31, 2020, at 6:53 AM, Rowan Tommins wrote: >> On 30/12/2020 21:24, Aleksander Machniak wrote: >>> My argument is that, from an end-user perspective, I don't really see >>> why Unit and Scalar enums have to have different

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-03 Thread Marc
On 29.12.20 16:42, Larry Garfield wrote: > On Tue, Dec 29, 2020, at 2:48 AM, Marc wrote: >> On 28.12.20 21:21, Larry Garfield wrote: >>> Hello, Internalians! >>> >>> After considerable discussion and effort, Ilija and I are ready to offer >>> you round 2 on enumerations. This is in the spirit

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-01 Thread Larry Garfield
On Fri, Jan 1, 2021, at 12:08 PM, Benjamin Eberlei wrote: > On Mon, Dec 28, 2020 at 9:22 PM Larry Garfield > wrote: > > > Hello, Internalians! > > > > After considerable discussion and effort, Ilija and I are ready to offer > > you round 2 on enumerations. This is in the spirit of the previous

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2021-01-01 Thread Benjamin Eberlei
On Mon, Dec 28, 2020 at 9:22 PM Larry Garfield wrote: > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer > you round 2 on enumerations. This is in the spirit of the previous > discussion, but based on that discussion a great deal has been

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-31 Thread Larry Garfield
On Thu, Dec 31, 2020, at 4:02 AM, Michał Marcin Brzuchalski wrote: > Hi Larry, > I really like the shape of the current RFC. > > I'd like to ask a few things: > > 1. Regarding the Scalar Enums since scalar values need to be literal and > by design they're read only why they use a spear

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-31 Thread Larry Garfield
On Thu, Dec 31, 2020, at 6:53 AM, Rowan Tommins wrote: > On 30/12/2020 21:24, Aleksander Machniak wrote: > > My argument is that, from an end-user perspective, I don't really see > > why Unit and Scalar enums have to have different "API" at this point. > > I'm talking about ":string"/":int" in the

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-31 Thread Rowan Tommins
On 30/12/2020 21:24, Aleksander Machniak wrote: My argument is that, from an end-user perspective, I don't really see why Unit and Scalar enums have to have different "API" at this point. I'm talking about ":string"/":int" in the enum definiton as well as ->value and ->from(). My personal

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-31 Thread Rowan Tommins
On 30/12/2020 19:47, Larry Garfield wrote: That's partially left over from when we had per-case methods, where grouping would be highly fugly. However, I'm still advocating for tagged unions (in a future step) having per-case methods, and that would make the grouping syntax fugly again.

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-31 Thread Michał Marcin Brzuchalski
Hi Larry, pon., 28 gru 2020 o 21:22 Larry Garfield napisał(a): > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer > you round 2 on enumerations. This is in the spirit of the previous > discussion, but based on that discussion a great deal has

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Aleksander Machniak
On 30.12.2020 21:21, Larry Garfield wrote: >> 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

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Larry Garfield
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

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 6:27 AM, Rowan Tommins wrote: > On 28/12/2020 20:21, Larry Garfield wrote: > > After considerable discussion and effort, Ilija and I are ready to offer > > you round 2 on enumerations. > > > Thank you both, again, for all your efforts. I'm pleased to say that I > like

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 4:12 AM, Alexandru Pătrănescu wrote: > Nice evolution overall. > > Few notes: > - I think ScalarEnum::fromValue() would be more clear than just from() and > more in sync with ->value property. Any name would work, I suppose. I prefer short, single-word methods where

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Aleksander Machniak
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';

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Larry Garfield
On Wed, Dec 30, 2020, at 2:43 AM, Markus Fischer wrote: > Hi, > > On 28.12.20 21:21, Larry Garfield wrote: > > The full RFC is here, and I recommend reading it again in full given how > > much was updated. > > > > https://wiki.php.net/rfc/enumerations > > I tried to answer the following

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Benjamin Morel
> > What's the quickest way (=less code) to have an enum represent it's > lexical name as the literal values? > > So that `… case Foo; case Bar; …` results in `::Foo->value === 'Foo'` etc.? > > Is this possible without implementing this manually for all cases? > > AFAICS, you'd need to implement

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Markus Fischer
On 30.12.20 12:00, Rowan Tommins wrote: On 30 December 2020 08:43:33 GMT+00:00, Markus Fischer wrote: What is the scalar value for a ScalarEnum if none is explicitly defined? The question has no answer, because the declaration of the enum itself would be invalid: If an enumeration is

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Rowan Tommins
On 28/12/2020 20:21, Larry Garfield wrote: After considerable discussion and effort, Ilija and I are ready to offer you round 2 on enumerations. Thank you both, again, for all your efforts. I'm pleased to say that I like this draft even more than the last one. :) A couple of points that

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Rowan Tommins
On 30 December 2020 08:43:33 GMT+00:00, Markus Fischer wrote: >What is the scalar value for a ScalarEnum if none is explicitly >defined? The question has no answer, because the declaration of the enum itself would be invalid: > If an enumeration is marked as having a scalar equivalent, then

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Alexandru Pătrănescu
On Mon, Dec 28, 2020 at 10:22 PM Larry Garfield wrote: > > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer you round 2 on enumerations. This is in the spirit of the previous discussion, but based on that discussion a great deal has been reworked.

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-30 Thread Markus Fischer
Hi, On 28.12.20 21:21, Larry Garfield wrote: The full RFC is here, and I recommend reading it again in full given how much was updated. https://wiki.php.net/rfc/enumerations I tried to answer the following question but failed to do so: What is the scalar value for a ScalarEnum if none is

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-29 Thread Larry Garfield
On Tue, Dec 29, 2020, at 2:48 AM, Marc wrote: > > On 28.12.20 21:21, Larry Garfield wrote: > > Hello, Internalians! > > > > After considerable discussion and effort, Ilija and I are ready to offer > > you round 2 on enumerations. This is in the spirit of the previous > > discussion, but based

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-29 Thread Marc
On 28.12.20 21:21, Larry Garfield wrote: > Hello, Internalians! > > After considerable discussion and effort, Ilija and I are ready to offer you > round 2 on enumerations. This is in the spirit of the previous discussion, > but based on that discussion a great deal has been reworked. The

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-28 Thread Larry Garfield
On Mon, Dec 28, 2020, at 6:40 PM, Benjamin Morel wrote: > Hi Larry, thank you for the updated RFC! > I love it, and having played with the implementation, I can say I love it > so far as well. > > I have one suggestion regarding reflection: > Shouldn't ReflectionCase expose an additional

Re: [PHP-DEV] [RFC] Enumerations, Round 2

2020-12-28 Thread Benjamin Morel
Hi Larry, thank you for the updated RFC! I love it, and having played with the implementation, I can say I love it so far as well. I have one suggestion regarding reflection: Shouldn't ReflectionCase expose an additional getInstance() method, that would return the case instance, such as

[PHP-DEV] [RFC] Enumerations, Round 2

2020-12-28 Thread Larry Garfield
Hello, Internalians! After considerable discussion and effort, Ilija and I are ready to offer you round 2 on enumerations. This is in the spirit of the previous discussion, but based on that discussion a great deal has been reworked. The main change is that Enumeration Cases are now object

Re: [PHP-DEV] [RFC] Enumerations

2020-12-14 Thread Paul Crovella
On Tue, Dec 8, 2020 at 10:14 AM Larry Garfield wrote: > > > Hi Paul. Although we're on hold for a bit while Ilija makes some changes in > direction (see previous email) I'm looking forward to seeing the results. > > Enumerations, as a general concept, are stateless. Or rather, the idea of >

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Lester Caine
On 04/12/2020 23:24, Larry Garfield wrote: The first step, for unit enumerations, is here: https://wiki.php.net/rfc/enumerations There's still a few bits we're sorting out and the implementation is mostly done, but not 100% complete. I use 'Enumerations' quite extensively but have not found

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Larry Garfield
On Wed, Dec 9, 2020, at 2:03 PM, Mike Schinkel wrote: > > Unless I'm missing something, trying to define "idempotence" or "pure > > functions" any more strictly than that would surely be a massive project in > > itself - for a start, you'd need a whitelist of all built-in operations > > which

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Mike Schinkel
> On Dec 9, 2020, at 3:29 PM, Benjamin Morel wrote: > > On Wed, 9 Dec 2020 at 19:48, Mike Schinkel > wrote: > > 5. Someone else mentioned shortcut syntax, which I would like to mention > again, although I realize implement details might make this a non-starter. >

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Benjamin Morel
On Wed, 9 Dec 2020 at 19:48, Mike Schinkel wrote: 5. Someone else mentioned shortcut syntax, which I would like to mention > again, although I realize implement details might make this a non-starter. > > So if I have a function that accepts a Size from above, e.g.: > > function show(Size $size)

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Mike Schinkel
> On Dec 9, 2020, at 2:06 PM, Rowan Tommins wrote: > > On 09/12/2020 18:47, Mike Schinkel wrote: >> 1. Will enum methods be idempotent? >> >> If not, shouldn't they be? > > > Can you clarify what you mean here? For a given parameter set the method would always return the same value. Note I

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Rowan Tommins
On 09/12/2020 18:47, Mike Schinkel wrote: 1. Will enum methods be idempotent? If not, shouldn't they be? Can you clarify what you mean here? The only meaningful question I can think of is "can they change the object's state?" That's mostly answered in the RFC, most notably by specifying

Re: [PHP-DEV] [RFC] Enumerations

2020-12-09 Thread Mike Schinkel
> On Dec 4, 2020, at 6: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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Dennis Birkholz
Am 08.12.20 um 18:40 schrieb Larry Garfield: > For serialization, we'll introduce a new serialization marker, enum, which > will make it feasible too round-trip an enum while maintaining > singleton-ness. More specifically, the deserialize routine would essentially > become

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Aleksander Machniak
On 08.12.2020 18:40, Larry Garfield wrote: > * We're going to shift Enums to be a single class with a bunch of secret > properties inside to hold the different case object instances, rather than a > class per case. That should make the overall memory usage lower, especially > for enums with a

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Pierre R.
Le 08/12/2020 à 18:40, Larry Garfield a écrit : On Sat, Dec 5, 2020, at 2:26 PM, Larry Garfield wrote: 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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Larry Garfield
On Sun, Dec 6, 2020, at 7:00 PM, Paul Crovella wrote: Hi Paul. Although we're on hold for a bit while Ilija makes some changes in direction (see previous email), I wanted to respond to your concerns in particular because it sounds like you're misunderstanding the scope and roadmap of what

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Larry Garfield
On Sat, Dec 5, 2020, at 2:26 PM, Larry Garfield wrote: > 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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-08 Thread Rowan Tommins
On 07/12/2020 20:20, Max Semenik wrote: I myself have tried to draft my proposal athttps://wiki.php.net/rfc/enum_v2 which has aspects both similar and different from yours. I'm afraid that proposal would be a strong -1 from me, as "fancy constants" are my least favourite type of enum. In

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Olle Härstedt
On Mon, 7 Dec 2020, 21:36 Olle Härstedt, wrote: > Did you discuss exhaustiveness checking already? > Nevermind, this is done by match already. > On Sat, 5 Dec 2020, 00:25 Larry Garfield, wrote: > >> Greetings, denizens of Internals! >> >> Ilija Tovilo and I have been working for the last few

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Olle Härstedt
On Sat, 5 Dec 2020, 15:43 Larry Garfield, wrote: > 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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Olle Härstedt
Did you discuss exhaustiveness checking already? On Sat, 5 Dec 2020, 00:25 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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Max Semenik
Thank you so much for moving this forward, Larry and Ilija! I myself have tried to draft my proposal at https://wiki.php.net/rfc/enum_v2 which has aspects both similar and different from yours. And "v2" is another indicator that this feature is desired by many, so yay. On Sat, Dec 5, 2020 at

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread tyson andre
Hi Nikita, > > At present, no.  They're "just" objects, and you can't assign an object > > to a constant.  Unfortunately I'm not sure how to enable that without > > making them not-objects, which introduces all sorts of other complexity. > > This should at the least be clarified in the RFC. Is

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Larry Garfield
On Mon, Dec 7, 2020, at 9:56 AM, Rowan Tommins wrote: > On 07/12/2020 15:26, Larry Garfield wrote: > > Assuming it's feasible to do, what do people feel about supporting that? > > IMO, cases(), from(), and values() need to be kept no matter what as > > they're more self documenting and can be

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Rowan Tommins
On 07/12/2020 15:26, Larry Garfield wrote: Assuming it's feasible to do, what do people feel about supporting that? IMO, cases(), from(), and values() need to be kept no matter what as they're more self documenting and can be passed around as callables. So the question is just whether we

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Pierre R.
Le 07/12/2020 à 16:26, Larry Garfield a écrit : On Mon, Dec 7, 2020, at 2:46 AM, Michał Marcin Brzuchalski wrote: Thanks for taking the topic. I love it. Regarding the `::cases()` method on UnitEnum I guess it'd be more natural to cast enum into an array like: (array) Suit; but I realize

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Larry Garfield
On Mon, Dec 7, 2020, at 2:46 AM, Michał Marcin Brzuchalski wrote: > Hi Larry, > > Thanks for taking the topic. I love it. > > Regarding the `::cases()` method on UnitEnum I guess it'd be more natural > to cast enum into an array like: > > (array) Suit; > > but I realize it'd be harder to

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Nikita Popov
On Sat, Dec 5, 2020 at 12:25 AM 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-07 Thread Brent Roose
Hi Larry and Ilja It's great to see you're looking into enums, thanks! I have a few considerations from a userland point of view. I've been maintaining a userland enum implementation for a while now [1] so I think I share a thing or two about my experience. - Scalar enums are spot on, exactly

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Rowan Tommins
On 07/12/2020 01:00, Paul Crovella wrote: Instance state being global is a well-known problem with singletons. Maybe don't use singletons then. Or simply document them as was done in the RFC. I'd prefer the former since singletons don't seem to buy much here but problems, though maybe I'm

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Michał Marcin Brzuchalski
Hi Larry, sob., 5 gru 2020 o 00:25 Larry Garfield napisał(a): > 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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-07 Thread Pierre R.
Le 07/12/2020 à 02:00, Paul Crovella a écrit : On Sun, Dec 6, 2020 at 7:12 AM Rowan Tommins wrote: Longer term plans are irrelevant except to avoid inadvertently shutting the door on something. This RFC is up for discussion, and will be up for voting, in isolation. It has to be able to stand on

Re: [PHP-DEV] [RFC] Enumerations

2020-12-06 Thread Paul Crovella
On Sun, Dec 6, 2020 at 7:49 AM Larry Garfield wrote: > > On Sun, Dec 6, 2020, at 9:11 AM, Rowan Tommins wrote: > > > Note that Larry's longer term plan is for "algebraic data types", > > including "tagged unions": https://wiki.php.net/rfc/adts Unlike > > straight-forward enum cases, these are not

Re: [PHP-DEV] [RFC] Enumerations

2020-12-06 Thread Paul Crovella
On Sun, Dec 6, 2020 at 7:12 AM Rowan Tommins wrote: > > On 06/12/2020 00:17, Paul Crovella wrote: > >> enum cases have no state > > Unless there's a bit left out from this RFC this is not completely > > true, you've just limited them to annoying ways of working with data, > > e.g. static

Re: [PHP-DEV] [RFC] Enumerations

2020-12-06 Thread Larry Garfield
On Sun, Dec 6, 2020, at 9:11 AM, Rowan Tommins wrote: > Note that Larry's longer term plan is for "algebraic data types", > including "tagged unions": https://wiki.php.net/rfc/adts Unlike > straight-forward enum cases, these are not singletons, and each instance > has its own associated state.

Re: [PHP-DEV] [RFC] Enumerations

2020-12-06 Thread Larry Garfield
On Sat, Dec 5, 2020, at 5:23 PM, Benjamin Morel wrote: > 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 >

Re: [PHP-DEV] [RFC] Enumerations

2020-12-06 Thread Rowan Tommins
On 06/12/2020 00:17, Paul Crovella wrote: enum cases have no state Unless there's a bit left out from this RFC this is not completely true, you've just limited them to annoying ways of working with data, e.g. static variables. I'm not sure what you mean here, but it sounds a bit like you're

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 > >>

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:

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

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

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 = [

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? >

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

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 >

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

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

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 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

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 > >

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

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

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

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

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

Re: [PHP-DEV] [RFC] Enumerations

2020-12-04 Thread Larry Garfield
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 >> support for enumerations and algebraic data types to PHP.  This is a >>

Re: [PHP-DEV] [RFC] Enumerations

2020-12-04 Thread 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 > support for enumerations and algebraic data types to PHP. This is a > not-small task, so we've broken it up into several

[PHP-DEV] [RFC] Enumerations

2020-12-04 Thread 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 first stage, unit enumerations, are just about ready for