yiisoft/yii2 · error · InvalidArgumentException

Argument $needles must be an array or implement Traversable

Error message

Argument $needles must be an array or implement Traversable

What it means

Error "Argument $needles must be an array or implement Traversable" thrown in yiisoft/yii2.

Source

Thrown at framework/helpers/BaseArrayHelper.php:910

    }

    /**
     * Checks whether an array or [[Traversable]] is a subset of another array or [[Traversable]].
     *
     * This method will return `true`, if all elements of `$needles` are contained in
     * `$haystack`. If at least one element is missing, `false` will be returned.
     *
     * @param iterable $needles The values that must **all** be in `$haystack`.
     * @param iterable $haystack The set of value to search.
     * @param bool $strict Whether to enable strict (`===`) comparison.
     * @return bool `true` if `$needles` is a subset of `$haystack`, `false` otherwise.
     * @throws InvalidArgumentException if `$haystack` or `$needles` is neither traversable nor an array.
     * @since 2.0.7
     */
    public static function isSubset($needles, $haystack, $strict = false)
    {
        if (!static::isTraversable($needles)) {
            throw new InvalidArgumentException('Argument $needles must be an array or implement Traversable');
        }

        foreach ($needles as $needle) {
            if (!static::isIn($needle, $haystack, $strict)) {
                return false;
            }
        }

        return true;
    }

    /**
     * Filters array according to rules specified.
     *
     * For example:
     *
     * ```
     * $array = [

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/helpers/BaseArrayHelper.php:910 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/7d8a7b6e52e03b7c. Report an issue: GitHub.