{"record":{"id":"adbdbc152f33222c","repo":"symfony/http-kernel","slug":"nested-closures-in-validation-groups-are-not-supported-use-a","errorCode":null,"errorMessage":"Nested closures in validation groups are not supported. Use a single Closure or a list of strings (or a GroupSequence) instead.","messagePattern":"Nested closures in validation groups are not supported\\. Use a single Closure or a list of strings \\(or a GroupSequence\\) instead\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver/RequestPayloadValueResolver.php","lineNumber":349,"sourceCode":"        if ($validationGroups instanceof Expression || $validationGroups instanceof \\Closure) {\n            $validationGroups = $event->evaluate($validationGroups, $this->expressionLanguage);\n        }\n\n        if (null === $validationGroups || \\is_string($validationGroups) || $validationGroups instanceof GroupSequence) {\n            return $validationGroups;\n        }\n\n        if (!\\is_array($validationGroups)) {\n            throw new \\LogicException('The validation groups expression or closure must return a string, an array of strings, or a GroupSequence.');\n        }\n\n        foreach ($validationGroups as $group) {\n            if ($group instanceof Expression) {\n                throw new \\LogicException('Nested expressions in validation groups are not supported. Use a single Expression or a list of strings (or a GroupSequence) instead.');\n            }\n\n            if ($group instanceof \\Closure) {\n                throw new \\LogicException('Nested closures in validation groups are not supported. Use a single Closure or a list of strings (or a GroupSequence) instead.');\n            }\n\n            if ($group instanceof GroupSequence) {\n                throw new \\LogicException('GroupSequence cannot be used inside an array of validation groups. Pass the GroupSequence as the top-level validationGroups value instead.');\n            }\n\n            if (!\\is_string($group)) {\n                throw new \\LogicException('Validation groups must be strings.');\n            }\n        }\n\n        return $validationGroups;\n    }\n\n    private static function hasNonStringScalar(array $data): bool\n    {\n        $stack = [$data];\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L331-L367","documentation":"If an array of validation groups contains a Closure element, Symfony throws this LogicException: only the top-level validationGroups value may be a closure; closures nested inside a group array are not evaluated.","triggerScenarios":"Returning [fn() => 'group', 'Other'] or otherwise placing a \\Closure inside the validationGroups array of a payload attribute.","commonSituations":"Misunderstanding that closures can be arbitrarily nested to compute individual groups; only the whole validationGroups value may be a closure.","solutions":["Move the closure to the top-level validationGroups value","Replace the nested closure with the string group it computes","Return only strings from the resolved groups"],"exampleFix":"// before\nvalidationGroups: [fn() => 'Strict', 'Default']\n// after\nvalidationGroups: fn() => ['Strict', 'Default']","handlingStrategy":"validation","validationCode":"foreach ($groups as $g) { if ($g instanceof \\Closure) { throw new \\InvalidArgumentException('no nested closures'); } }","typeGuard":"!($group instanceof \\Closure)","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'Nested closures')) { /* hoist closure to top level */ } throw $e; }","preventionTips":["Only the whole validationGroups value may be a Closure","Resolve nested closures to strings before passing","Centralize group computation in one closure"],"tags":["symfony","validation","closure","groups"],"backgroundTag":"unsupported-operation","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"}