Crell / enum-comparison

A comparison of enumerations and similar features in different languages
82 stars 7 forks source link

Fast method to get only the name of a case? #60

Closed TysonAndre closed 3 years ago

TysonAndre commented 3 years ago

Possibly redundant since case Hearts = 'Hearts' can be used if you really want to use the name to identify cases, but after removing $value->name you'd need ReflectionEnumCase or explode('::', var_export($value, true))[1] if you wanted the enum name (e.g. for a debugging statement such as printf("Handling %s\n", repr($enum))

Compiled languages often don't provide this, but dynamic ones might

iluuu1994 commented 3 years ago

We've come full circle ^^ Well, I would honestly just prefer keeping the case property. It also technically makes more sense than keeping a hashmap for the case names.

TysonAndre commented 3 years ago

Well, I would honestly just prefer keeping the case property.

Same.

That approach also makes it easier for libraries to attempt to partially polyfill this before 8.1 (e.g. also define public static function Hearts() { return self::Hearts; /* or something else in 8.0 and older */ }) (if code used the name)

iluuu1994 commented 3 years ago

@Crell As we've agreed to keep this property now after all, can you add it to the RFC?

Crell commented 3 years ago

->case is now added to the first section ("Unit Enums").