-
-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value-less enum #7
Comments
I like the feature idea. I'm not so sure about the suggested implementation though, it's really not consistent with the current "syntax". IMO it's not a big deal to give values 1, 2, 3, … Especially since I often find that the |
Yeah, the syntax is a bit iffy... |
The idea is very valid. @mnapoli the argument that you have to handle your values with care kinda defeats the purpose of enums (as they are defined e.g. in Java). The implementation as I'd see it:
It's totally doable, but the structure would have to change a bit (because this version wouldn't have a notion of keys and values). If you like my view of it, I think I could have a shot in couple of days. |
Very true, my argument was more of "the gain/cost ratio is not really high, so I'd rather favor consistency". In a "true" enum implementation you are right values are optional. The
I think the most gain we could get would be to have a native PHP implementation (hint hint @TazeTSchnitzel :p). |
Surely, |
This is doable with the existing implementation, if you take advantage of constant scopes:
Your enum still technically has a value, but the value is explicitly defined as an implementation detail rather than exposed as relevant to the rest of the application. (A further enhancement could return null or throw an exception on |
Here's another idea:
Perhaps a variant of this class which doesn't have a value for each enum member, so
SomeEnum::FOO
doesn't work butSomeEnum::FOO()
does? Could be used like so in PHP 5.6:Or something like that. Maybe not a good idea. What do you think?
The text was updated successfully, but these errors were encountered: