ZF-6815: Zend_Validate_Interface::isValid() argument list is incorrect


the argument list ($value) differs from documentation and rest of code in zend framework ($value, $context). adding second argument to interface causes application to crash at initialisation of Zend_Form class.


According to documentation $context is part of Zend_Form and not of Zend_Validate.

Zend_Validate does for now not support $context as this feature does not match to all validators. This Zend_Form feature is not part of the interface of Zend_Validate. Maybe in future but not for now.

@Matthew: Do you want to change documentation to reflect this like in the other issue ? Otherwise I would propose to close this issue as there is already a feature request.

My opinion is that context should not be added to Zend_Validate's interface. It would not match for most of the available validators. What should a "Int" or "Date" validator do with $context ? Also some validators already provide a second argument which is used differently than context. They would all have to be rewritten. This could also apply to user-land validators.

According to Zend_Form validation and context I was said that I have to add a new form-validator which would then also support context additionally to form element validation. But this would be one or more specialized form validators for form elements and not all other standard validators.

If $context is added as an optional argument, it does not break the interface, and this is in fact how we document using the $context variable within the Zend_Form documentation. Simply modify your code slightly:

class MyValidator extends Zend_Validate_Abstract
    public function isValid($value, $context = null)
        if (null === $context) {
            // optionally, you can make it required via logical conditions...
            throw new Exception('This validator requires a context array');
        // ...

There is no need for additional validator interfaces or abstract classes with this strategy.