Affects Version/s: 1.2.1
Fix Version/s: 1.2.3
At the moment:
- Doctrine_Table::enumIndex($fieldName, $value) returns $value specified as a parameter if no index for it is found
- Doctrine_Table::enumValue($fieldName, $index) returns $index specified as a parameter if no value for it is found
This actually makes writing code which deals with enums a bit difficult as one would like to detect incorrect parameter as soon as possible (e.g. not when Doctrine validation kicks in and checks that enum value is incorrect).
Current algorithm that returns index or value is not sufficient to determine error in situation when index=value, e.g. enum values are [0, 1, 2, 3]. Calling e.g. enumValue('sample', 4) would yield 4 - so it makes difficult to determine whether it's correct value.
I hope this makes sense, let me know if anything is unclear.
The workaround for this is to check whether mapped index/value exists in array returned by Doctrine_Table::getEnumValues(), but this is an extra unnecessary check.
So instead of writing:
I'd like to write: