Zend Framework

validator greaterThan with value 0 issues warning

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.7.0
  • Fix Version/s: 1.8.1
  • Component/s: Zend_Form
  • Labels:
    None

Description

In a subclass of a form, I have the following code:

$this->addElement('text', 'from', array(
'label' => 'From',
'required' => true,
'validators' => array('digits', array('greaterThan', false, 0)),
'size' => 15,
));
$this->addElement('text', 'to', array(
'label' => 'To',
'required' => true,
'validators' => array('digits', array('greaterThan', false, 1)),
'size' => 15,
));

This leads to the following warnings:

Warning: Missing argument 1 for Zend_Validate_GreaterThan::__construct(), called in D:\Projects\...\...\library\Zend\Form\Element.php on line 2000 and defined in D:\Projects\...\...\library\Zend\Validate\GreaterThan.php on line 68
Call Stack

  1. Time Memory Function Location
    1 0.0739 90776 {main}( ) ..\index.php:0
    2 0.2249 4957736 Zend_Controller_Front->dispatch( ???, ??? ) ..\index.php:54
    3 0.2350 5316368 Zend_Controller_Dispatcher_Standard->dispatch( ???, ??? ) ..\Front.php:934
    4 0.2544 5690424 Zend_Controller_Action->dispatch( ??? ) ..\Standard.php:285
    5 0.2545 5692328 TestController->geocodeAction( ) ..\Action.php:503
    6 0.3275 8391568 Zend_Form->isValid( ??? ) ..\TestController.php:38
    7 0.3277 8393664 Zend_Form_Element->isValid( ???, ??? ) ..\Form.php:1987
    8 0.3279 8396472 Zend_Form_Element->getValidators( ) ..\Element.php:1283
    9 0.3317 8476808 Zend_Form_Element->_loadValidator( ??? ) ..\Element.php:1210
    10 0.3338 8495256 Zend_Validate_GreaterThan->__construct( ??? ) ..\Element.php:2000

    ( ! ) Notice: Undefined variable: min in D:\Projects\...\...\library\Zend\Validate\GreaterThan.php on line 70
    Call Stack
    # Time Memory Function Location
    1 0.0739 90776 {main}( ) ..\index.php:0
    2 0.2249 4957736 Zend_Controller_Front->dispatch( ???, ??? ) ..\index.php:54
    3 0.2350 5316368 Zend_Controller_Dispatcher_Standard->dispatch( ???, ??? ) ..\Front.php:934
    4 0.2544 5690424 Zend_Controller_Action->dispatch( ??? ) ..\Standard.php:285
    5 0.2545 5692328 TestController->geocodeAction( ) ..\Action.php:503
    6 0.3275 8391568 Zend_Form->isValid( ??? ) ..\TestController.php:38
    7 0.3277 8393664 Zend_Form_Element->isValid( ???, ??? ) ..\Form.php:1987
    8 0.3279 8396472 Zend_Form_Element->getValidators( ) ..\Element.php:1283
    9 0.3317 8476808 Zend_Form_Element->_loadValidator( ??? ) ..\Element.php:1210
    10 0.3338 8495256 Zend_Validate_GreaterThan->__construct( ??? ) ..\Element.php:2000

This obviously has to do with PHP treating 0 as empty().

I guess that other validators, at least lessThan, but others probably as well, also suffer from this bug.

Activity

Hide
Thomas Weidner added a comment -

The GreaterThan validator has no problems with "0".
Even unittests exist for testing this value.

As there is wether an empty() nor an other method call within the GreaterThan validator, I expect that the main problem is within Zend_Form, and not Zend_validate_GreaterThan.

Also the given failure message let me expect this.
A not given parameter, as returned within the php exception, is not a case which could be handled by the class itself.

Show
Thomas Weidner added a comment - The GreaterThan validator has no problems with "0". Even unittests exist for testing this value. As there is wether an empty() nor an other method call within the GreaterThan validator, I expect that the main problem is within Zend_Form, and not Zend_validate_GreaterThan. Also the given failure message let me expect this. A not given parameter, as returned within the php exception, is not a case which could be handled by the class itself.
Hide
Thomas Weidner added a comment -

I'm not able to verify this issue against Zend_Validate_GreaterThan within trunk.
I expect that this failure is part of Zend_Form_Element's. Otherwise it can be closed as non-issue.

Show
Thomas Weidner added a comment - I'm not able to verify this issue against Zend_Validate_GreaterThan within trunk. I expect that this failure is part of Zend_Form_Element's. Otherwise it can be closed as non-issue.
Hide
Rob Knight added a comment -

'validators' => array('digits', array('greaterThan', false, 0)),

This should be:

'validators' => array('digits', array('greaterThan', false, array(0))),

Not your fault though, there isn't really much documentation on the array declaration syntax for validators (or for forms generally).

Show
Rob Knight added a comment - 'validators' => array('digits', array('greaterThan', false, 0)), This should be: 'validators' => array('digits', array('greaterThan', false, array(0))), Not your fault though, there isn't really much documentation on the array declaration syntax for validators (or for forms generally).
Hide
Thomas Weidner added a comment -

Closing as non-issue.

Show
Thomas Weidner added a comment - Closing as non-issue.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: