{"record":{"id":"3235c0ea34a3ac4a","repo":"symfony/routing","slug":"the-definition-of-s-in-s-must-be-an-array","errorCode":null,"errorMessage":"The definition of \"%s\" in \"%s\" must be an array.","messagePattern":"The definition of \"(.+?)\" in \"(.+?)\" must be an array\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/ContentLoaderTrait.php","lineNumber":209,"sourceCode":"            if (null !== $namePrefix) {\n                $subCollection->addNamePrefix($namePrefix);\n            }\n            $subCollection->addDefaults($defaults);\n            $subCollection->addRequirements($requirements);\n            $subCollection->addOptions($options);\n\n            $collection->addCollection($subCollection);\n        }\n    }\n\n    /**\n     * @throws \\InvalidArgumentException If one of the provided config keys is not supported,\n     *                                   something is missing or the combination is nonsense\n     */\n    private function validate(mixed $config, string $name, string $path): void\n    {\n        if (!\\is_array($config)) {\n            throw new \\InvalidArgumentException(\\sprintf('The definition of \"%s\" in \"%s\" must be an array.', $name, $path));\n        }\n        if (isset($config['alias'])) {\n            $this->validateAlias($config, $name, $path);\n\n            return;\n        }\n        if ($extraKeys = array_diff(array_keys($config), self::AVAILABLE_KEYS)) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" contains unsupported keys for \"%s\": \"%s\". Expected one of: \"%s\".', $path, $name, implode('\", \"', $extraKeys), implode('\", \"', self::AVAILABLE_KEYS)));\n        }\n        if (isset($config['resource']) && isset($config['path'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The routing file \"%s\" must not specify both the \"resource\" key and the \"path\" key for \"%s\". Choose between an import and a route definition.', $path, $name));\n        }\n        if (!isset($config['resource']) && isset($config['type'])) {\n            throw new \\InvalidArgumentException(\\sprintf('The \"type\" key for the route definition \"%s\" in \"%s\" is unsupported. It is only available for imports in combination with the \"resource\" key.', $name, $path));\n        }\n        if (!isset($config['resource']) && !isset($config['path'])) {\n            throw new \\InvalidArgumentException(\\sprintf('You must define a \"path\" for the route \"%s\" in file \"%s\".', $name, $path));\n        }","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/ContentLoaderTrait.php#L191-L227","documentation":"The validate() method requires each named routing definition to be an array (a map of config keys). If the parsed value for a route name is a scalar, null, or anything non-array, an InvalidArgumentException is thrown because none of the route/import config can be read from it.","triggerScenarios":"A YAML entry like `home: /` (scalar) instead of `home: { path: / }`; a PHP config array where the route name maps to a string or boolean; mis-indented YAML collapsing a definition into a scalar.","commonSituations":"YAML indentation mistakes making a definition a plain string; config assembled programmatically with wrong nesting; empty values assigned to route names.","solutions":["Make the definition a map: home: { path: '/', controller: ... }.","Fix YAML indentation so route options are nested under the route name.","Check programmatic config builders for accidental scalar assignment."],"exampleFix":"// before\n'home' => '/',\n// after\n'home' => ['path' => '/'],","handlingStrategy":"validation","validationCode":"foreach ($defs as $name => $def) { if (!\\is_array($def)) { throw new \\InvalidArgumentException(\"Definition '{$name}' must be an array\"); } }","typeGuard":"function isRouteDefinition(mixed $def): bool { return \\is_array($def); }","tryCatchPattern":"try { $loader->load($file); } catch (\\InvalidArgumentException $e) { /* fix the scalar definition named in the message */ }","preventionTips":["Every route name must map to a nested map of options.","Validate YAML indentation with a schema linter.","Never assign plain strings to route names in config builders."],"tags":["routing","config-validation","yaml-config","symfony"],"backgroundTag":"config-type-mismatch","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}