I'm using Zend_Filter_Input to filter and validate my data. For a field (gender), I am using the Zend_Validate_InArray to validate, if the value is in
array('m', 'w');
So far so good.
While running my UnitTests, I noticed, that an empty array is a valid value for gender, too.
To analyze this, I wrote the following code:
$genderArray = array('m', 'w');
$needle = array();
if(in_array($needle, $genderArray)) {
Zend_Debug::dump('is in array');
} else {
Zend_Debug::dump('is not in array');
}
$validator = new Tueks_Validate_InArray($genderArray);
if ($validator->isValid($needle)) {
Zend_Debug::dump('is in array');
} else {
Zend_Debug::dump('is not in array');
}
Both times, I got 'is not in array'.
But when I use the following code:
$child = new Tueks_Placereport_Child();
$child->setGender($needle);
$child->validate();
everything works fine (--> array() ist part of array('m', 'w'))?!?
Here is the relevant part from my validate-method:
$genderArray = array('m', 'w');
$filters = array();
$validators = array('gender'=>
array('presence'=> 'required',
new Tueks_Validate_InArray($genderArray)
)
);
$input = new Zend_Filter_Input($filters, $validators, $this->_data);
Tueks_Validate_InArray is the same like Zend_Validate_InArray, but with other messages. I don't see the problem, why, when using Zend_Filter_Input, an empty array is a valid value. Hope you can help me.