A free and open-source book on ZF3 for beginners

8.5. Filter's Behavior in Case of Incorrect Input Data

Different filters behave differently if you pass it input data that the filter cannot process correctly.

Some filters (such as the ToInt filter) will process only scalar data. If you pass an array to such filter, it will return the array as is.

Some filters can work with data in certain format only (e.g., with dates only). If filtering of input data is impossible (for example, when you pass the filter some wrong data that it is unable to process), the filter() method may throw a Zend\Filter\Exception\RuntimeException exception. This behavior can be seen in DateTimeFormatter filter.

Some filters (e.g., ToInt or StringToLower) may rise a PHP warning if the value provided is in incorrect format and cannot be filtered.

It is recommended to read filter's documentation carefully to know what to expect of the filter you plan to use in your form.