A free and open-source book on ZF3 for beginners

8.1. About Filters

Filters are designed to take some input data, process it, and produce some output data. Zend Framework 3 provides a lot of standard filters that can be used for creating filtering rules of your forms (or, if you wish, to filter an arbitrary data outside of forms).

8.1.1. FilterInterface

Technically, a filter is a PHP class implementing the FilterInterface interface (it belongs to Zend\Filter namespace). The interface definition is presented below:

namespace Zend\Filter;

interface FilterInterface
    // Returns the result of filtering $value.
    public function filter($value);

As you can see, the FilterInterface interface has the single method filter() (line 7), which takes the single parameter $value. The method transforms the input data and finally returns the resulting (filtered) value.

A concrete filter class implementing the FilterInterface interface may have additional methods. For example, many filter classes have methods allowing configuration of the filter (set filtering options).