ZF-8903: Zend_Validate_Float requires $locale to be a locale or specifically null

Description

As of 1.10.0 it appears that Zend_Validate_Float requires the locale to be either specifically null or a locale. This is all well and good except when used with Zend_Form an empty array is sent to the validator instead of null. Therefore Zend_Validate_Float tries to retrieve the locale 'array' which obviously doesn't exist!

The quick fix is to add a quick empty() check on the $locale and set the locale to null.

The problem occurs when you set messages and pass options into Zend_Form_Element. If there are no options set then nothing is passed to the validator. If only messages are set an empty array is set. If the first element of the array is the value then it all works fine. The first element can be a locale or null and it works as expected.

In short the default null value is being overwritten and the validator requires it to be null when it should be empty.

It worked fine in 1.9.7.

The below code passes an empty array to the validator:


'validators' => array(
    array('Float', true,
        array('messages' => array(
         Zend_Validate_Float::NOT_FLOAT => 'The quantity should be a number.',
    )
        )
)
)

The below code works as expected:


'validators' => array(
    array('Float', true,
        array(null,
        'messages' => array(
         Zend_Validate_Float::NOT_FLOAT => 'The quantity should be a number.',
    )
        )
)
)

Comments

Also before 1.10 Zend_Validate_Float allowed to give a null or a locale.

Fixed Zend_Form_Element as with r20538