symfony/http-kernel · error · InvalidArgumentException

The action argument "...$%1$s" is required to be an array…

Error message

The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.

What it means

VariadicValueResolver fetches the request attribute named after the variadic controller argument and requires it to be an array. If the attribute exists but holds a scalar/object, this InvalidArgumentException is thrown because ...$arg can only consume array values.

Solutions

  1. Ensure the request attribute value is an array (wrap scalars in an array)
  2. Rename the variadic argument to avoid attribute-name collisions
  3. Cast route defaults to arrays when defining the route

Example fix

// before
$attributes->set('ids', '1');
// after
$attributes->set('ids', ['1']);
Defensive patterns

Strategy: type-guard

Validate before calling

$values = $request->attributes->get($name); if (null !== $values && !is_array($values)) { throw new \InvalidArgumentException("$name attribute must be array"); }

Type guard

is_array($request->attributes->get($argumentName))

Try / catch

try { $response = $kernel->handle($request); } catch (\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'required to be an array')) { /* fix attribute value */ } throw $e; }

Prevention

When it happens

Trigger: A route/controller sets a request attribute (e.g. via a listener or _controller_defaults) with a scalar value whose name collides with a variadic action argument, e.g. public function foo(...$ids) while attributes->get('ids') is a string.

Common situations: Route default values being strings while the action declares ...$param, or custom listeners setting single values under the same key.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/79499d17f213a3a1. Report an issue: GitHub.

Appendix: source

Thrown at Controller/ArgumentResolver/VariadicValueResolver.php:34

use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
 * Yields a variadic argument's values from the request attributes.
 *
 * @author Iltar van der Berg <kjarli@gmail.com>
 */
final class VariadicValueResolver implements ValueResolverInterface
{
    public function resolve(Request $request, ArgumentMetadata $argument): array
    {
        if (!$argument->isVariadic() || !$request->attributes->has($argument->getName())) {
            return [];
        }

        $values = $request->attributes->get($argument->getName());

        if (!\is_array($values)) {
            throw new \InvalidArgumentException(\sprintf('The action argument "...$%1$s" is required to be an array, the request attribute "%1$s" contains a type of "%2$s" instead.', $argument->getName(), get_debug_type($values)));
        }

        return $values;
    }
}

View on GitHub (pinned to aa3a39d728)