ZF-6175: Zend_Validate_Float fails in localized environment

Issue Type: Bug Created: 2009-04-01T03:21:53.000+0000 Last Updated: 2009-04-04T12:54:42.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Danne Lundqvist (dotvoid) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


Floats and thus the function floatval() used to test filtered value in Zend_Validate_Float::isValid() is locale aware and return value with localized decimal_point. Thus the test will always fail when a locale is set which uses a decimal point other than ".". Tested with PHP

When... setlocale(LC_ALL, 'sv_SE.UTF-8'); $value = 10.5;

...this will always fail as it results in a comparison between "10,5" and "10.5". if (strval(floatval($valueFiltered)) != $valueFiltered) { $this->_error(); return false; }

Proposed solution

list($num, $dec) = explode('.', $valueFiltered); if (strval(intval($num)) != $num || strval(intval($dec)) != $dec) { $this->_error(); return false; }

There are also no unit test Zend_Validate_Float with a locale other than default.


Posted by Thomas Weidner (thomas) on 2009-04-04T12:54:42.000+0000

This new feature has been added 3 months ago. It will be released with 1.8.

Have you found an issue?

See the Overview section for more details.


© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

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