Closed
Description
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:
class EnumFixture extends Enum
{
const FOO = "bar";
const PROBLEMATIC_NUMBER = 0;
const PROBLEMATIC_NULL = null;
const PROBLEMATIC_EMPTY_STRING = '';
const PROBLEMATIC_BOOLEAN_FALSE = false;
}
EnumFixture::search(false); // PROBLEMATIC_NUMBER
EnumFixture::search(''); // PROBLEMATIC_NUMBER
EnumFixture::search(null); // PROBLEMATIC_NUMBER
EnumFixture::search('bar I do not exist'); // PROBLEMATIC_NUMBER
EnumFixture::search(array()); // PROBLEMATIC_NULL
EnumFixture::search(0); // FOO ***WTF***
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
Metadata
Metadata
Assignees
Labels
No labels