{"record":{"id":"20440c5f9dfdbdc4","repo":"symfony/routing","slug":"route-pattern-s-cannot-contain-s-as-a-path-parameter","errorCode":null,"errorMessage":"Route pattern \"%s\" cannot contain \"%s\" as a path parameter.","messagePattern":"Route pattern \"(.+?)\" cannot contain \"(.+?)\" as a path parameter\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"RouteCompiler.php","lineNumber":86,"sourceCode":"        if (null !== $locale && null !== $route->getDefault('_canonical_route') && preg_quote($locale) === $route->getRequirement('_locale')) {\n            $requirements = $route->getRequirements();\n            unset($requirements['_locale']);\n            $route->setRequirements($requirements);\n            $route->setPath(str_replace('{_locale}', $locale, $route->getPath()));\n        }\n\n        $path = $route->getPath();\n\n        $result = self::compilePattern($route, $path, false);\n\n        $staticPrefix = $result['staticPrefix'];\n\n        $pathVariables = $result['variables'];\n\n        foreach ($pathVariables as $pathParam) {\n            // \"_firewall\" selects the firewall handling the route; as a path parameter it would let the URL choose it\n            if ('_fragment' === $pathParam || '_firewall' === $pathParam) {\n                throw new \\InvalidArgumentException(\\sprintf('Route pattern \"%s\" cannot contain \"%s\" as a path parameter.', $route->getPath(), $pathParam));\n            }\n        }\n\n        $variables = array_merge($variables, $pathVariables);\n\n        $tokens = $result['tokens'];\n        $regex = $result['regex'];\n\n        return new CompiledRoute(\n            $staticPrefix,\n            $regex,\n            $tokens,\n            $pathVariables,\n            $hostRegex,\n            $hostTokens,\n            $hostVariables,\n            array_unique($variables)\n        );","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/RouteCompiler.php#L68-L104","documentation":"RouteCompiler throws this when a route path contains a variable named \"_fragment\" or \"_firewall\". Both are reserved names: \"_fragment\" selects the fragment renderer and \"_firewall\" selects the firewall handling the route; allowing them as path parameters would let the request URL choose them. compile() raises an InvalidArgumentException as soon as such a path variable is found.","triggerScenarios":"Compiling a route whose path contains {_fragment} or {_firewall}, e.g. ->setPath('/{_firewall}/dashboard') or a YAML route path '/{_fragment}/foo'.","commonSituations":"Typos or misunderstandings of Symfony's reserved route attributes; copying _controller-style underscore naming conventions to arbitrary parameter names; dynamically generated route paths that include reserved keys.","solutions":["Rename the path variable to a non-reserved name, e.g. /{section}/dashboard instead of /{_firewall}/dashboard.","Remove the variable if it was added by mistake and pass the value via defaults or controller arguments instead.","Search route config files for \"_fragment\" and \"_firewall\" used as {placeholders}."],"exampleFix":"// before\n$route->setPath('/{_firewall}/dashboard');\n\n// after\n$route->setPath('/{area}/dashboard');","handlingStrategy":"validation","validationCode":"$reserved = ['_fragment', '_firewall'];\nforeach ($reserved as $name) {\n    if (preg_match('#\\{'.preg_quote($name, '#').'\\}#', $route->getPath())) {\n        throw new \\InvalidArgumentException(\"Path must not contain reserved {{$name}} parameter.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    (new RouteCompiler())->compile($route);\n} catch (\\InvalidArgumentException $e) {\n    // log and skip/fail fast for the offending route definition\n}","preventionTips":["Treat all underscore-prefixed parameter names as reserved in paths.","Lint route config (YAML/attributes) in CI for {_fragment} and {_firewall} placeholders.","Use plain names for regular parameters and pass special values via defaults."],"tags":["routing","symfony","reserved-parameter","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}