Crell / enum-comparison

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

from/has scalar in reflection #63

Closed iluuu1994 closed 3 years ago

iluuu1994 commented 3 years ago

From reflection it's currently not possible to get a case from a scalar. Reflection should probably be able to do that.

bwoebi commented 3 years ago

technically you can do $reflectionEnum->getMethod("has")->invoke(null, $someValue); … And practically $reflectionEnum->getName()::has($value);

iluuu1994 commented 3 years ago

@bwoebi Sure, but is that generally considered enough? Many things in PHP can be done without reflection ($foo->{$bar}) but they are generally also possible through reflection.

bwoebi commented 3 years ago

I don't care :-D I never use the reflection way unless I have access permission issues (which cannot happen here).

Crell commented 3 years ago

Honestly, I'm fine with these not being accessible through reflection directly. If you're in a reflection context you can always get from there to the actual case object and then call the appropriate methods. I'm also fine if Ilija wants to add it. I don't care much either way.

iluuu1994 commented 3 years ago

Well, let's leave it then :laughing: