{"record":{"id":"38a07d579400ec36","repo":"symfony/http-kernel","slug":"validation-groups-must-be-strings","errorCode":null,"errorMessage":"Validation groups must be strings.","messagePattern":"Validation groups must be strings\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Controller/ArgumentResolver/RequestPayloadValueResolver.php","lineNumber":357,"sourceCode":"        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\n        while ($stack) {\n            foreach (array_pop($stack) as $v) {\n                if (\\is_array($v)) {\n                    $stack[] = $v;\n                } elseif (!\\is_string($v) && !\\is_object($v)) {\n                    // uploaded files are merged into the payload of a \"form\" request; being objects,\n                    // they are not scalars and must not make the payload look like a typed one\n                    return true;","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ArgumentResolver/RequestPayloadValueResolver.php#L339-L375","documentation":"After excluding Expression, Closure, and GroupSequence elements, every remaining element of a validation-groups array must be a plain string. Any other scalar/object element causes this LogicException.","triggerScenarios":"Passing validationGroups: ['Default', 42] or an array containing null/enum objects to a payload attribute's validationGroups.","commonSituations":"Using integer constants for groups, forgetting to cast backed enums to strings, or building the groups array dynamically with mixed values.","solutions":["Convert non-string group values to strings (e.g. $enum->value)","Fix the group constants to be string constants","Filter/normalize the groups array before returning it from the closure"],"exampleFix":"// before\nvalidationGroups: fn() => [Group::Strict, 'Default']\n// after\nvalidationGroups: fn() => [Group::Strict->value, 'Default']","handlingStrategy":"validation","validationCode":"foreach ($groups as $g) { if (!is_string($g)) { throw new \\InvalidArgumentException('group must be string'); } }","typeGuard":"is_array($groups) && array_all($groups, 'is_string')","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'must be strings')) { /* stringify group values */ } throw $e; }","preventionTips":["Use string constants for groups","Cast backed enums with ->value","Validate the groups array shape in unit tests"],"tags":["symfony","validation","type-error","groups"],"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"}