ZF-7843: Zend_Validate_NotEmpty and null values

Description

Since ZF 1.9.0 when you try to validate a null value with Zend_Validate_NotEmpty you get the INVALID error message instead of the IS_EMPTY error message.

If you try:

$value     = null;
$validator = new Zend_Validate_NotEmpty();

Zend_Debug::dump($validator->isValid($value));
Zend_Debug::dump($validator->getErrors());
Zend_Debug::dump($validator->getMessages());

since ZF 1.9.0 it results in:

bool(false)

array(1) {
 [0] => string(15) "notEmptyInvalid"
}

array(1) {
 ["notEmptyInvalid"] => string(76) "Invalid type given, value should be float, string, array, boolean or integer"
}

before ZF 1.9.0 it would result in:

bool(false)

array(1) {
 [0] => string(7) "isEmpty"
}

array(1) {
 ["isEmpty"] => string(36) "Value is required and can't be empty"
}

I believe the expected behavior is to get the IS_EMPTY and not the INVALID error type.

A fix for this would be to check that the value is not null before checking its type (in Zend/Validate/NotEmpty.php on line 56)

if (null !== $value && !is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value) &&
    !is_array($value)) {
    $this->_error(self::INVALID);
    return false;
} 

This issue might be related to #ZF-7631

Comments

No it's not dependend... Validating objects does not make sense as objects are ALWAYS filled and can not be empty.

Tested with next mini release. Unable to reproduce. Probably already fixed in past.

I just checked and you're right, it has been fixed in r18092

Right between when I posted the issue and last time I checked the repository.

Thanks

No problem... it's fixed, and that's all what counts ;-)