{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/41","labels_url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/41/comments","events_url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/41/events","html_url":"https://github.com/zendframework/zend-stdlib/issues/41","id":113587373,"number":41,"title":"ArrayUtils::inArray should use strict in_array?","user":{"login":"adamlundrigan","id":527329,"avatar_url":"https://avatars.githubusercontent.com/u/527329?v=3","gravatar_id":"","url":"https://api.github.com/users/adamlundrigan","html_url":"https://github.com/adamlundrigan","followers_url":"https://api.github.com/users/adamlundrigan/followers","following_url":"https://api.github.com/users/adamlundrigan/following{/other_user}","gists_url":"https://api.github.com/users/adamlundrigan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamlundrigan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamlundrigan/subscriptions","organizations_url":"https://api.github.com/users/adamlundrigan/orgs","repos_url":"https://api.github.com/users/adamlundrigan/repos","events_url":"https://api.github.com/users/adamlundrigan/events{/privacy}","received_events_url":"https://api.github.com/users/adamlundrigan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zendframework/zend-stdlib/labels/awaiting%20maintainer%20response","name":"awaiting maintainer response","color":"fbca04"},{"url":"https://api.github.com/repos/zendframework/zend-stdlib/labels/BC%20Break","name":"BC Break","color":"e11d21"}],"state":"open","locked":false,"assignee":{"login":"Ocramius","id":154256,"avatar_url":"https://avatars.githubusercontent.com/u/154256?v=3","gravatar_id":"","url":"https://api.github.com/users/Ocramius","html_url":"https://github.com/Ocramius","followers_url":"https://api.github.com/users/Ocramius/followers","following_url":"https://api.github.com/users/Ocramius/following{/other_user}","gists_url":"https://api.github.com/users/Ocramius/gists{/gist_id}","starred_url":"https://api.github.com/users/Ocramius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ocramius/subscriptions","organizations_url":"https://api.github.com/users/Ocramius/orgs","repos_url":"https://api.github.com/users/Ocramius/repos","events_url":"https://api.github.com/users/Ocramius/events{/privacy}","received_events_url":"https://api.github.com/users/Ocramius/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2015-10-27T13:48:46Z","updated_at":"2015-10-27T20:51:47Z","closed_at":null,"body":"Related: https://github.com/zendframework/zend-form/issues/18\r\n\r\nIn [`Zend\\Form\\View\\Helper\\FormSelect`](https://github.com/zendframework/zend-form/blob/767ed409dc19b127d36ed4cdc01de0318207b50b/src/View/Helper/FormSelect.php#L206) `ArrayUtils::inArray` is called with the strict parameter `false`.  This causes an issue with string matching ('1.1' and '1.10' treated equivalent):\r\n\r\n```php\r\n<?php\r\n$needle = '1.10';\r\n$haystack = ['1.1'];\r\n\r\nassert(in_array($needle, $haystack) === false);\r\n// PHP Warning:  assert(): Assertion failed in <file> on line 5\r\n```\r\n(3v4l: https://3v4l.org/HKM8Q)\r\n\r\nSimply changing FormSelect to use strict=true breaks [an existing test which uses integer keys in the value options array](https://github.com/zendframework/zend-form/blob/767ed409dc19b127d36ed4cdc01de0318207b50b/test/View/Helper/FormSelectTest.php#L367-L385).\r\n\r\nSince `ArrayUtils::inArray` uses string casting to work around `in_array`'s wonky non-strict behaviour, shouldn't the call to `in_array` always have strict=true?\r\n\r\n```diff\r\ndiff --git a/src/ArrayUtils.php b/src/ArrayUtils.php\r\nindex 17e3ae3..69b9721 100644\r\n--- a/src/ArrayUtils.php\r\n+++ b/src/ArrayUtils.php\r\n@@ -199,7 +199,7 @@ abstract class ArrayUtils\r\n                 }\r\n             }\r\n         }\r\n-        return in_array($needle, $haystack, $strict);\r\n+        return in_array($needle, $haystack, true);\r\n     }\r\n \r\n     /**\r\n```\r\n\r\nI've tested this change here (all tests pass) and against `zend-form` (where it fixes the reported issue).  \r\n\r\nWhat's the protocol for testing changes to packages which may have knock-on effects on other packages?  Pull every repo that has a dependency on stdlib, apply the patch, and run the tests? "},"comment":{"url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/comments/151639922","html_url":"https://github.com/zendframework/zend-stdlib/issues/41#issuecomment-151639922","issue_url":"https://api.github.com/repos/zendframework/zend-stdlib/issues/41","id":151639922,"user":{"login":"adamlundrigan","id":527329,"avatar_url":"https://avatars.githubusercontent.com/u/527329?v=3","gravatar_id":"","url":"https://api.github.com/users/adamlundrigan","html_url":"https://github.com/adamlundrigan","followers_url":"https://api.github.com/users/adamlundrigan/followers","following_url":"https://api.github.com/users/adamlundrigan/following{/other_user}","gists_url":"https://api.github.com/users/adamlundrigan/gists{/gist_id}","starred_url":"https://api.github.com/users/adamlundrigan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamlundrigan/subscriptions","organizations_url":"https://api.github.com/users/adamlundrigan/orgs","repos_url":"https://api.github.com/users/adamlundrigan/repos","events_url":"https://api.github.com/users/adamlundrigan/events{/privacy}","received_events_url":"https://api.github.com/users/adamlundrigan/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T20:51:47Z","updated_at":"2015-10-27T20:51:47Z","body":"Marco asked same question above: https://github.com/zendframework/zend-stdlib/issues/41#issuecomment-151625729\r\n\r\nIt breaks an existing test in FormSelect.  The `value_options` array for Select can contain integer keys, which are converted to string when rendered by FormSelect.  With a strict check alone that will fail since the haystack has \"int 0\" but the form data has \"string 0\".  The only workaround that works for both cases is to pass \"false\" to `ArrayUtils::inArray` (so it casts everything to strings) but pass \"true\" to `in_array` to get strict matching.  That's what the code in my PR does. "}}