{"record":{"id":"492e6c466c07e50a","repo":"symfony/http-kernel","slug":"could-not-resolve-the-argument-typed-s-valid-types-are-array","errorCode":null,"errorMessage":"Could not resolve the argument typed \"%s\". Valid types are \"array\", \"string\" or \"%s\".","messagePattern":"Could not resolve the argument typed \"(.+?)\"\\. Valid types are \"array\", \"string\" or \"(.+?)\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver/RequestHeaderValueResolver.php","lineNumber":36,"sourceCode":"use Symfony\\Component\\HttpKernel\\Controller\\ValueResolverInterface;\nuse Symfony\\Component\\HttpKernel\\ControllerMetadata\\ArgumentMetadata;\nuse Symfony\\Component\\HttpKernel\\Exception\\HttpException;\nuse Symfony\\Component\\HttpKernel\\Exception\\NearMissValueResolverException;\n\nfinal class RequestHeaderValueResolver implements ValueResolverInterface, SourceValueResolverInterface\n{\n    public function resolve(Request $request, ArgumentMetadata $argument): array\n    {\n        if (!$attribute = $argument->getAttributesOfType(MapRequestHeader::class)[0] ?? null) {\n            return [];\n        }\n\n        $type = $argument->getType();\n        $name = $attribute->name ?? strtolower(preg_replace('/[a-z]\\K[A-Z]/', '-$0', $argument->getName()));\n\n        if (!\\in_array($type, ['string', 'array', AcceptHeader::class])) {\n            if (null === $type || $argument->isVariadic() || !class_exists($type) && !interface_exists($type)) {\n                throw new \\LogicException(\\sprintf('Could not resolve the argument typed \"%s\". Valid types are \"array\", \"string\" or \"%s\".', $type, AcceptHeader::class));\n            }\n\n            if (!$request->headers->has($name)) {\n                if ($argument->isNullable() || $argument->hasDefaultValue()) {\n                    return [];\n                }\n\n                throw HttpException::fromStatusCode($attribute->validationFailedStatusCode, \\sprintf('Missing header \"%s\".', $name));\n            }\n\n            // Stage the raw header under the argument name so that a resolver able to build this type,\n            // such as DateTimeValueResolver or UidValueResolver, picks it up from the attributes.\n            $request->attributes->set($argument->getName(), $request->headers->get($name));\n\n            throw new NearMissValueResolverException(\\sprintf('#[MapRequestHeader] cannot build controller argument \"$%s\" of type \"%s\" by itself; no resolver converted the staged value.', $argument->getName(), $type));\n        }\n\n        $value = null;","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestHeaderValueResolver.php#L18-L54","documentation":"RequestHeaderValueResolver handles #[MapHeader]/header-attribute arguments and only supports argument types string, array, or Symfony\\Component\\HttpFoundation\\AcceptHeader. It throws LogicException when the argument type is anything else that is not even class/interface-like, or is null/variadic — i.e. a type the resolver can never construct from a header.","triggerScenarios":"Declaring #[MapHeader] (or legacy header mapping) on an argument typed int/bool/float, an untyped argument, a variadic argument, or a class that does not exist in the container-aware check (class_exists/interface_exists false).","commonSituations":"Assuming headers are auto-cast to int/bool like query params; expecting custom DTOs from headers; typos in use-statements leading to nonexistent class names; upgrading code that previously resolved other scalar types.","solutions":["Type the argument as string or array (AcceptHeader for Accept-style headers).","Cast manually: take the string and convert to int/bool in the controller body.","Fix the class name if the type was meant to be an existing class/interface supported by the resolver."],"exampleFix":"// before\npublic function index(#[MapHeader('x-page')] int $page) {}\n// after\npublic function index(#[MapHeader('x-page')] string $page) {}\n$page = (int) $page;","handlingStrategy":"type-guard","validationCode":"$t = $param->getType();\nif (!$t instanceof \\ReflectionNamedType || !in_array($t->getName(), ['string','array',\\Symfony\\Component\\HttpFoundation\\AcceptHeader::class], true)) { /* retype argument */ }","typeGuard":"function isHeaderArgumentSupported(\\ReflectionParameter $p): bool\n{\n    $t = $p->getType();\n    return $t instanceof \\ReflectionNamedType\n        && !$p->isVariadic()\n        && in_array($t->getName(), ['string','array',\\Symfony\\Component\\HttpFoundation\\AcceptHeader::class], true);\n}","tryCatchPattern":"try { $args = $resolver->getArguments($request, $controller); } catch (\\LogicException $e) { /* retype header argument to string/array/AcceptHeader */ }","preventionTips":["Type header arguments as string or array only","Cast to int/bool manually inside the controller","Use AcceptHeader for content-negotiation headers"],"tags":["symfony","controller","header","argument-resolver"],"backgroundTag":"type-mismatch","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}