zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

Warning: A non-numeric value encountered #225

Closed atanaspuskulev closed 6 years ago

atanaspuskulev commented 6 years ago

Hello,

Validating a form email address with a \Zend\Validator\EmailAddress or \Zend\Validator\Hostname triggers an warning and does not properly validates.

OS: Windows 10 64bit, PHP: PHP 7.1.8 (cli) (built: Aug 1 2017 21:10:31) ( NTS MSVC14 (Visual C++ 2015) x86 )

Code to reproduce:

$filter->add(array(
            'name' => 'email',
            'required' => true,
            'filters' => array(
                array('name' => 'StringTrim')
            ),
            'validators' => array(
                array(
                    'name' => 'EmailAddress',
                    'options' => array(
                        'allow' => \Zend\Validator\EmailAddress::class,
                        'useMxCheck' => false
                    )
                ),
                array(
                    ........
                )
            )
        ));

Output:

Warning: A non-numeric value encountered in D:\htdocs\project\vendor\zendframework\zend-validator\src\Hostname.php on line 2010

Warning: A non-numeric value encountered in D:\htdocs\project\vendor\zendframework\zend-validator\src\Hostname.php on line 2160

Warning: A non-numeric value encountered in D:\htdocs\project\vendor\zendframework\zend-validator\src\Hostname.php on line 2168

Warning: A non-numeric value encountered in D:\htdocs\project\vendor\zendframework\zend-validator\src\Hostname.php on line 2182

froschdesign commented 6 years ago

The warning is correct, because you are using a wrong value for the option allow.

$validator = new Zend\Validator\EmailAddress(
    [
        'allow'      => \Zend\Validator\Hostname::ALLOW_ALL, // <-- See here!
        'useMxCheck' => false,
    ]
);

var_dump($validator->isValid('mail@example.com')); // true

Compare with the documentation and the supported options.


Please reduce your code example. Your problem is the validator. So there is no need to include zend-inputfilter and zend-filter. This will help us and we can help you much faster. Thanks!

atanaspuskulev commented 6 years ago

Thanks!