ZF2-411: Validator\InArray not able to compare string values to ints

Issue Type: Bug Created: 2012-07-20T00:26:56.000+0000 Last Updated: 2012-07-26T19:47:20.000+0000 Status: Resolved Fix version(s): Reporter: Thomas R. (thomas_r) Assignee: Maks 3w (maks3w) Tags: - Zend\Validator

  • InArray
  • Validator

Related issues: Attachments:


With the check for int 0 in haystack at the start of InArray::isValid, comparing input against ints becomes impossible unless strict mode is enabled. Of course, if trying to compare string "0" against int 0, then it's impossible as a strict check will fail, and you don't have the option to not use strict mode owing to the exception being thrown because int 0 is in haystack.

Fix is simple - remove the check that throws an exception at the start of the method along with the unit test. Maybe a better unit test should be devised that tests "0" against array(0,5,10) which passes with strict false, and fails on strict true.

The original 'issue' ( where the developer is comparing a string against an int 0 will return true when any string that doesn't start with a digit is tested against int 0. The original bug report is incorrect, "6asdf" will return 6, not int 0 as suggested by the bug reporter. That's correct PHP behaviour and a bug of the developer, not a bug of ZF2.


Posted by Thomas R. (thomas_r) on 2012-07-20T00:56:02.000+0000

i've submitted a pr

Posted by Maks 3w (maks3w) on 2012-07-20T00:56:28.000+0000

Against "asdf6" will be valid.

You can write your own validator extending from the original if you need a different behavior, but IMHO must exists a code to warning the developer about unexpected behaviors due a the ""normal"" behavior of PHP.

Posted by Thomas R. (thomas_r) on 2012-07-20T00:59:30.000+0000

No need to extend, this is now broken. It's not the framework's job to report upon gotcha's on PHP. With the check it prevents testing strings against int 0. This is a fairly major zf bug.

Again, ZF2 should not modify expected behaviour of PHP.

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.