zendframework / zend-inputfilter

InputFilter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
64 stars 50 forks source link

Missing `false` as generic empty value #138

Closed autowp closed 6 years ago

Erikvv commented 7 years ago

I don't think it is useful to consider false as empty, I don't remember ever wanting that.

But it is consistent with Zend\Validator\NotEmpty

autowp commented 7 years ago

A usage example is posting json to RESTful API and filter incoming data with optional boolean fields.

Whatever "field is required" message to an optional field is always incorrect regardless of wanting that by someone.

Erikvv commented 7 years ago

I don't understand what you're trying to say.

Ocramius commented 7 years ago

Tests are required anyway: a test will clarify the ambiguity

weierophinney commented 6 years ago

I agree with @Erikvv here. If you are submitting values via an API, and have an actual boolean false value submitted, the value is not empty. In those cases, you're likely expecting a boolean, and you would want to validate it as such. If the value is supposed to be another type entirely, I'd argue allowing false as an empty value would be inconsistent, because if you allow_empty, you're now getting a value of the wrong type.

As such, I'm closing this request. If you feel strongly about it, re-open with unit tests, and discussion of the specific use cases.