> We tried that. The `enum` keyword precludes any class or interface being called `Enum`, even internally.
Enumerable, Enumerated, Enumerator? On Mon, Feb 1, 2021 at 7:30 PM Larry Garfield <la...@garfieldtech.com> wrote: > On Mon, Feb 1, 2021, at 11:48 AM, Alexandru Pătrănescu wrote: > > > > > https://wiki.php.net/rfc/enumerations > > > > > > At this point, Ilija and I consider the RFC done and ready for a vote. > > > Baring any major issues being brought up, we plan to start the vote in > the > > > first half of next week, probably Tuesday-ish. If you have any other > bug > > > reports or tweaks, please speak now or forever hold your patches. > > > > > > --Larry Garfield > > > > > > > > Hi, > > > > Maybe IterableEnum can actually be just Enum. As you are not allowed to > > implement it and/or define it, wouldn't it work? That's how it's named > > internally in Java, not that it would matter but sometimes people forget > > it's just syntactic sugar there as well ( > > https://docs.oracle.com/javase/8/docs/api/java/lang/Enum.html): public > > abstract class Enum<E extends Enum<E>> implements Comparable<E>, > > Serializable. > > We tried that. The `enum` keyword precludes any class or interface being > called `Enum`, even internally. > > > Also in the interface I think you can include the name property, > similarly > > with how you did in BackedEnum interface. > > https://wiki.php.net/rfc/property_accessors will probably allow it to be > > clearly defined at some point. > > > > A bit it bothers me that backed enums are very easy to implement even > > without the special case and just a simple Enum would be fine. > > I mean even if you will have a backed enum, with would be simple and > > probably the need will come at some point to have also a public function > > getLegacyValue(): string and a public static function > > fromLegacyValue(string $value): Enum. > > But yes, using backed values is a common pattern so I'm guessing it's a > > valuable important use case. > > It's more about standardizing the API. An ORM can rely on a backed enum > always exposing its "value to save to the DB" at ->value, rather than it > sometimes being ->value(), sometimes ->legacyValue(), sometimes ->asInt(), > etc. > > > For storing in a database purpose, property name can be used directly, I > > think. > > It would nice to have in the rfc the recommended way to retrieve the > Enum, > > given that you know the name. > > I'm guessing that would be Suit::$name; > > That doesn't work for referencing a constant; it gets read as a static > property. That's a more general syntactic question for PHP, and one we're > not going to solve here. :-) Really, ->name is more an implementation > artifact. If you want to have a primitive to pass around, for whatever > reason, that's what a backed enum is for. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >