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

Issue Type: Bug Created: 2009-05-26T23:58:38.000+0000 Last Updated: 2009-05-27T05:35:48.000+0000 Status: Resolved Fix version(s): Reporter: Joshua Hogendorn (devians) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

  • Zend_Validate

Related issues: Attachments:


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.


Posted by Thomas Weidner (thomas) on 2009-05-27T00:50:12.000+0000

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.

Posted by Matthew Weier O'Phinney (matthew) on 2009-05-27T05:35:30.000+0000

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:

<pre class="highlight">
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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.