ZF-8868: Zend_Validate_Int validates floats?

Issue Type: Bug Created: 2010-01-19T05:25:32.000+0000 Last Updated: 2010-01-27T10:11:21.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Ota Mares (ota) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


"The integers are formed by the natural numbers including 0 (0, 1, 2, 3, ...) together with the negatives of the non-zero natural numbers (−1, −2, −3, ...). Viewed as subset of the real numbers, they are numbers that can be written without a fractional or decimal component, and fall within the set {... −2, −1, 0, 1, 2, ...}. For example, 65, 7, and −756 are integers; 1.6 and 1½ are not integers." []

Basically its just a naming issue but in some cases it can lead to confusion why floats are accepted by Zend_Validate_Int as an int does consist only of natural numbers. Maybe there is a special reason or i am confusing something big time?, but a more logic name would be Zend_Validate_Number.

<pre class="highlight">require_once 'Zend/Validate/Int.php
$foo = new Zend_Validate_Int();



Posted by Thomas Weidner (thomas) on 2010-01-21T14:47:42.000+0000

Using your example on latest release I get: 1. true 2. false 3. false

In my eyes this is correct behaviour. I see no problems.

Posted by Thomas Weidner (thomas) on 2010-01-21T14:48:27.000+0000

Closing as fixed for next release. Probably already fixed within the last 7 months.

Posted by Ota Mares (ota) on 2010-01-22T01:56:29.000+0000

Hi Thomas, i found the culprit. The validator is dependent on the specified locale and i think that shouldnt be? :)

Using following code will return true in all three cases:

<pre class="highlight"><?php 
setlocale(LC_ALL, 'de_DE.utf8');
require_once 'Zend/Debug.php';
require_once 'Zend/Validate/Int.php';
$foo = new Zend_Validate_Int();


Posted by Thomas Weidner (thomas) on 2010-01-22T02:32:34.000+0000

But the system relies on this locale. Also PHP relies on this locale.

Why should then Zend_Validate_Int not rely in this locale when you don't specify a locale at all?

Zend_Validate_Int then uses system-settings which also PHP uses. In my eyes this is correct behaviour.

There is only one difference... when you specified a Zend_Locale object within your registry, then this object will be used instead of system settings. But this is not given due to your example.

Posted by Ota Mares (ota) on 2010-01-22T04:33:08.000+0000

Because an integer is allways an integer and that is a natural number, independent of the locale. It doesnt matter if you are in brazil or germany, an integer is allways the same.

And thats why the validator is confusing, it does not validate if the number is an integer but a numerical value alltogether. Simply said, the validator does not do what its name implys.

How about renaming the validator? I am also confused about Zend_Validate_Digit, for me it seems that Zend_Validate_Int should be named Zend_Validate_Digit and the digit validator should be ditched alltogether.

Posted by Thomas Weidner (thomas) on 2010-01-22T10:30:33.000+0000

I still don't see your problem...

As said also your second example returns true for the first, but false on the other two testcases.

Posted by Ota Mares (ota) on 2010-01-25T00:57:49.000+0000

I just redownloaded the ZF-1.9.7 minimal package to be sure. The testcode from the comments above returns true on all three zend_debug::dump cases. There is nothing else in the directory besides the zf and the test file.

I am trying to prove there is an issue, and i can reproduce it. I dont know what else todo.

Maybe some other users could test it on their systems?

Posted by Ota Mares (ota) on 2010-01-25T01:34:31.000+0000

Oh also i just tested it on my hosting webspace, same issue. You can view the "test" at following site:…

Posted by Thomas Weidner (thomas) on 2010-01-25T11:08:15.000+0000

When you say that this issue occurs with 1.9.7 then I also expect that you are using 1.9.7.

On the other hand, when I say that this issue is fixed with the next minor release (which is the upcoming 1.10) then I expect that you tested it with 1.10 when you say that the issue is still there.

Don't you think? ;-)

Posted by Ota Mares (ota) on 2010-01-27T07:24:36.000+0000

Duh, i interpreted your message as if it allready was fixed seven months ago and that it should work in the current 1.9.7 release.

Posted by Thomas Weidner (thomas) on 2010-01-27T10:11:21.000+0000

Looking above at "Fix-Versions" you can see that it reads "1.10.0", which is the actual release. :-)

7 months was the time between the fix and the next minor release. Some API changes and additional have been done. Therefor it was not possible to backport the changes to 1.9.x.

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.