{"record":{"id":"cd248865ca0db375","repo":"yiisoft/yii2","slug":"argument-haystack-must-be-an-array-or-implement-t","errorCode":null,"errorMessage":"Argument $haystack must be an array or implement Traversable","messagePattern":"Argument \\$haystack must be an array or implement Traversable","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"framework/helpers/BaseArrayHelper.php","lineNumber":863,"sourceCode":"\n    /**\n     * Check whether an array or [[Traversable]] contains an element.\n     *\n     * This method does the same as the PHP function [in_array()](https://www.php.net/manual/en/function.in-array.php)\n     * but additionally works for objects that implement the [[Traversable]] interface.\n     *\n     * @param mixed $needle The value to look for.\n     * @param iterable $haystack The set of values to search.\n     * @param bool $strict Whether to enable strict (`===`) comparison.\n     * @return bool `true` if `$needle` was found in `$haystack`, `false` otherwise.\n     * @throws InvalidArgumentException if `$haystack` is neither traversable nor an array.\n     * @see https://www.php.net/manual/en/function.in-array.php\n     * @since 2.0.7\n     */\n    public static function isIn($needle, $haystack, $strict = false)\n    {\n        if (!static::isTraversable($haystack)) {\n            throw new InvalidArgumentException('Argument $haystack must be an array or implement Traversable');\n        }\n\n        if (is_array($haystack)) {\n            return in_array($needle, $haystack, $strict);\n        }\n\n        foreach ($haystack as $value) {\n            if ($strict ? $needle === $value : $needle == $value) {\n                return true;\n            }\n        }\n\n        return false;\n    }\n\n    /**\n     * Checks whether a variable is an array or [[Traversable]].\n     *","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/helpers/BaseArrayHelper.php#L845-L881","documentation":"Error \"Argument $haystack must be an array or implement Traversable\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/helpers/BaseArrayHelper.php:863 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}