{"record":{"id":"802cebcbc5e2c7dd","repo":"symfony/http-kernel","slug":"could-not-resolve-the-s-controller-argument-argument-should","errorCode":null,"errorMessage":"Could not resolve the \"$%s\" controller argument: argument should be typed.","messagePattern":"Could not resolve the \"\\$(.+?)\" controller argument: argument should be typed\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver/RequestPayloadValueResolver.php","lineNumber":129,"sourceCode":"        $arguments = $event->getArguments();\n\n        foreach ($arguments as $i => $argument) {\n            if ($argument instanceof MapQueryString) {\n                $payloadMapper = $this->mapQueryString(...);\n                $validationFailedCode = $argument->validationFailedStatusCode;\n            } elseif ($argument instanceof MapRequestPayload) {\n                $payloadMapper = $this->mapRequestPayload(...);\n                $validationFailedCode = $argument->validationFailedStatusCode;\n            } elseif ($argument instanceof MapUploadedFile) {\n                $payloadMapper = $this->mapUploadedFile(...);\n                $validationFailedCode = $argument->validationFailedStatusCode;\n            } else {\n                continue;\n            }\n            $request = $event->getRequest();\n\n            if (!$argument->metadata->getType()) {\n                throw new \\LogicException(\\sprintf('Could not resolve the \"$%s\" controller argument: argument should be typed.', $argument->metadata->getName()));\n            }\n\n            if ($this->validator) {\n                $violations = new ConstraintViolationList();\n                try {\n                    $payload = $payloadMapper($request, $argument->metadata, $argument);\n                } catch (PartialDenormalizationException $e) {\n                    $trans = $this->translator ? $this->translator->trans(...) : static fn ($m, $p) => strtr($m, $p);\n                    $errors = method_exists($e, 'getNotNormalizableValueErrors') ? $e->getNotNormalizableValueErrors() : $e->getErrors();\n                    foreach ($errors as $error) {\n                        $parameters = [];\n                        $template = 'This value was of an unexpected type.';\n                        if ($expectedTypes = $error->getExpectedTypes()) {\n                            $template = 'This value should be of type {{ type }}.';\n                            $parameters['{{ type }}'] = implode('|', $expectedTypes);\n                        }\n                        if ($error->canUseMessageForUser()) {\n                            $parameters['hint'] = $error->getMessage();","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L111-L147","documentation":"During onKernelControllerArguments, if the mapped controller argument has no type declaration, Symfony cannot instantiate or validate a payload for it and throws this LogicException. Every argument resolved via MapQueryString/MapRequestPayload must have a class or type declaration.","triggerScenarios":"A controller argument annotated with #[MapQueryString] or #[MapRequestPayload] that has no type hint (e.g. function index($payload)) — exercised by tests like testNotTypedArgument and testDefaultValueArgument.","commonSituations":"Refactoring away a type hint, copy-pasting an attribute onto an untyped argument, or relying on docblock types which the resolver ignores.","solutions":["Add a class or built-in type declaration to the annotated argument","Remove the payload attribute if the argument is not meant to be mapped","Use a DTO class as the argument type"],"exampleFix":"// before\npublic function index(#[MapQueryString] $filter) {}\n// after\npublic function index(#[MapQueryString] SearchFilter $filter) {}","handlingStrategy":"type-guard","validationCode":"foreach ($annotatedParams as $p) { if (!$p->getType()) { throw new \\TypeError(\"{$p->name} needs a type for payload mapping\"); } }","typeGuard":"if ($param->getType() instanceof \\ReflectionNamedType && !$param->getType()->isBuiltin() || $param->getType()?->isBuiltin()) { /* typed */ }","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'argument should be typed')) { /* add type hint */ } throw $e; }","preventionTips":["Always type-hint arguments carrying mapping attributes","Enable deprecation/static analysis (phpstan) on controllers","Never rely on docblock types for the resolver"],"tags":["symfony","logic-exception","type-hint","argument-resolver"],"backgroundTag":"missing-required-argument","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"}