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


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.


i've submitted a pr

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.

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.