Re: [RFC] Enumerations, Round 2
| From: | Markus Fischer | Date: | Mon, 04 Jan 2021 15:12:42 +0000 |
| Subject: | Re: [RFC] Enumerations, Round 2 | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112748@lists.php.net to get a copy of this message | ||
Hi,
On 04.01.21 15:05, Rowan Tommins wrote:
On 04/01/2021 11:15, Markus Fischer wrote:I can't say whether justOn 03.01.21 12:01, Mike Schinkel wrote:I would personally be OK with this if it was allowed but opt-in, e.g. adding the ": string" would default the values in that way, or even something magic like ": auto".So in my perfect world this: enum BookingStatus {I'm with Mikes' suggesting here, see also my previous messages [1] [2]. I don't know how to back this up with numbers, but the way I see it the majority of use cases will have a benefit of being able to directly use the literal values derived from the lexical ones and the ability to have custom values is feature next to it.case PENDING; case CONFIRMED; case CANCELLED;} Would be equivalent to: enum BookingStatus {case PENDING = "PENDING"; case CONFIRMED = "CONFIRMED"; case CANCELLED = "CANCELLED";}
: 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 smarter idea :)
Maybe not evident, I like the enum RFC but think the most value for many use cases will having automatically values.
thanks!
- Markus