-
-
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
Construction of enum object with invalid value is possible #95
Comments
Thanks, that's an interesting problem 🤔 I'm wondering if all Enums should not be made final? (i.e. recommended in the docs) Because inheritance doesn't work here: yes |
IMO the problem is here: The value should either be validated anyway, or passing an Enum instance to Enum constructor should not be allowed at all. Or maybe instead of instanceof check, you should check |
As I said I think the problem is more global. function (Enum1 $value) Here an instance of So I really think inheritance is incompatible with enums in general. |
The above error is the result of incorrect use of the enum pattern in the application. But this does not mean that it is forbidden, there are times when it is really needed. Solution in PR #97 |
Nice, that's exactly what I would have suggested, unless I got distracted by other stuff... :/ Thanks, @KartaviK |
Check this sample:
Expected exception, instead got A3 printed.
throws as expected.
The text was updated successfully, but these errors were encountered: