You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on how you choose consts values in your Enum class, it can have very undesirable effects. This is because the library uses in_array (constructor) and array_search (new search method) without strict checking. To get the notion of what I mean, please look at: https://ideone.com/FvouJm
The same can happen if you use many other problematic values like null, booleans, empty string etc. While majority of them are impractical to use, having value as integer 0 is. My point is, if you chose to have such a weird values, it's up to you, but the library should never allow to create enums from out of range.
You can really see the problem when you create enums from user input:
converting query strings params to enums
creating enums from arguments in php CLI apps
I think it'd be worthwhile to add that to docs too. I have a PR ready with the fix, just needs some styling changes. What do you think ?
tl;dr You can create enums from out of defined values
class MyEnum extends Enum {
const A = 0;
const B = 1;
}
new MyEnum('any string'); // SUCCESS but it should throw \UnexpectedValueException
The text was updated successfully, but these errors were encountered:
Depending on how you choose consts values in your Enum class, it can have very undesirable effects. This is because the library uses
in_array
(constructor) andarray_search
(new search method) without strict checking. To get the notion of what I mean, please look at: https://ideone.com/FvouJmThe same can happen if you use many other problematic values like null, booleans, empty string etc. While majority of them are impractical to use, having value as integer 0 is. My point is, if you chose to have such a weird values, it's up to you, but the library should never allow to create enums from out of range.
You can really see the problem when you create enums from user input:
I think it'd be worthwhile to add that to docs too. I have a PR ready with the fix, just needs some styling changes. What do you think ?
tl;dr You can create enums from out of defined values
The text was updated successfully, but these errors were encountered: