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
New search() method has a contract to find enum by value and return corresponding key. Logically, this method should return boolean false when nothing found or a key, which is always a string (not integer), as internally key => value pairs are kept as associative array with string keys. Because search() uses array_search without strict param, it can find a wrong key:
This is the same kind of a problem as #9. The fix is to simply enable strict checking on search. Yes, you should not use such values, but the last search example shows problem even if you use proper values. I can take care of this if you want @mnapoli
The text was updated successfully, but these errors were encountered:
mirfilip
changed the title
Search() is not type safe
search() is not type safe
Feb 9, 2015
mirfilip
added a commit
to mirfilip/php-enum
that referenced
this issue
Feb 9, 2015
New
search()
method has a contract to find enum by value and return corresponding key. Logically, this method should return boolean false when nothing found or a key, which is always a string (not integer), as internallykey => value
pairs are kept as associative array with string keys. Becausesearch()
usesarray_search
without strict param, it can find a wrong key:This is the same kind of a problem as #9. The fix is to simply enable strict checking on search. Yes, you should not use such values, but the last
search
example shows problem even if you use proper values. I can take care of this if you want @mnapoliThe text was updated successfully, but these errors were encountered: