Re: [Discussion] Implicitly backed enums

From: Date: Tue, 21 May 2024 23:47:42 +0000
Subject: Re: [Discussion] Implicitly backed enums
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 22/05/2024 00:31, Larry Garfield wrote:
I could see an argument for auto-populating the backing value off the enum name if it's not specified, something like this: enum Options: string { case First; // This implicitly gets "First" case Second = '2nd'; }
This seems like a reasonable compromise. In this case, all I need to do is change my enum to a backed enum (suffix : string) and I get the benefits of implicit values. I still like the idea of the same being possible for non-backed enums, though I imagine that is a product of my naïveté, as I do not tend to think of things in the framing of (de)serialization.
I'm not sure if I'd support it myself at the moment
Noted, but I once again find myself needing to ask: why not? Were it up to me, I'd say let's start right now! :) Aside, I am not at all concerned with integer-backed enums at this juncture, and presume that could be a separate discussion/implementation anyway. Cheers, Bilge

Thread (21 messages)

« previous php.internals (#123393) next »