yiisoft/yii2 · error · InvalidArgumentException
Argument $haystack must be an array or implement Traversable
Error message
Argument $haystack must be an array or implement Traversable
What it means
Error "Argument $haystack must be an array or implement Traversable" thrown in yiisoft/yii2.
Source
Thrown at framework/helpers/BaseArrayHelper.php:863
/**
* Check whether an array or [[Traversable]] contains an element.
*
* This method does the same as the PHP function [in_array()](https://www.php.net/manual/en/function.in-array.php)
* but additionally works for objects that implement the [[Traversable]] interface.
*
* @param mixed $needle The value to look for.
* @param iterable $haystack The set of values to search.
* @param bool $strict Whether to enable strict (`===`) comparison.
* @return bool `true` if `$needle` was found in `$haystack`, `false` otherwise.
* @throws InvalidArgumentException if `$haystack` is neither traversable nor an array.
* @see https://www.php.net/manual/en/function.in-array.php
* @since 2.0.7
*/
public static function isIn($needle, $haystack, $strict = false)
{
if (!static::isTraversable($haystack)) {
throw new InvalidArgumentException('Argument $haystack must be an array or implement Traversable');
}
if (is_array($haystack)) {
return in_array($needle, $haystack, $strict);
}
foreach ($haystack as $value) {
if ($strict ? $needle === $value : $needle == $value) {
return true;
}
}
return false;
}
/**
* Checks whether a variable is an array or [[Traversable]].
*View on GitHub (pinned to 66f00d18a2)
When it happens
Trigger: Thrown at framework/helpers/BaseArrayHelper.php:863 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17).
Data as JSON: /api/errors/cd248865ca0db375.
Report an issue: GitHub.