ZF-9968: NotEmpty Validator treats objects as empty


I am referring to issue ZF-7631. There is claimed that Zend_Validate_NotEmpty does not accept anything other than string, boolean etc.

Although I basically agree with Thomas' post, that it does not make sense to check an object for emptiness, I wonder why it treats objects as empty by default rather than as "notEmpty". I came over that issue when trying to validate a Zend_Date object with the input filter. The property's presence is required, which makes Zend_Filter_Input add an NotEmpty-Validator to the chain. As all objects are always treated as empty, my date object does never get the chance to meet Zend_Validate_Date.

So please consider to change the default behaviour to "notEmpty" for objects instead of "empty". If null is passed instead of the object, it then should hit "empty", as expected. This issue impacts the filter chains of zend_filter_input.

Thanks for looking into the matter again.


Zend_Validate_NotEmpty returns an failure and states: "Invalid type given, value should be float, string, array, boolean or integer"

The same would apply to resources, connections or other non-scalar inputs.

The thing is: When you give a false input, you can't rely on a correct functional behaviour of a validator. False means "failure"... which type of failure has to be checked.

When we switch the behaviour of the validator to return "true" for all types which are not recognised it would also be treated as false behaviour.

New feature implemented with r22663