{"record":{"id":"2c03a47b6b1dbb27","repo":"symfony/routing","slug":"the-container-parameter-s-resolves-to-an-env-var-which-is","errorCode":null,"errorMessage":"The container parameter \"%s\" resolves to an env var, which is not allowed in routing configuration.","messagePattern":"The container parameter \"(.+?)\" resolves to an env var, which is not allowed in routing configuration\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DependencyInjection/Router.php","lineNumber":181,"sourceCode":"\n        if (!\\is_string($value)) {\n            return $value;\n        }\n\n        $escapedValue = preg_replace_callback('/%%|%([^%\\s]++)%/', function ($match) use ($value) {\n            // skip %%\n            if (!isset($match[1])) {\n                return '%%';\n            }\n\n            if (preg_match('/^env\\((?:\\w++:)*+\\w++\\)$/', $match[1])) {\n                throw new RuntimeException(\\sprintf('Using \"%%%s%%\" is not allowed in routing configuration.', $match[1]));\n            }\n\n            $resolved = ($this->paramFetcher)($match[1]);\n\n            if (\\is_string($resolved) && preg_match('/env_[a-f0-9]{16}_\\w+_[a-f0-9]{32}/Ui', $resolved)) {\n                throw new RuntimeException(\\sprintf('The container parameter \"%s\" resolves to an env var, which is not allowed in routing configuration.', $match[1]));\n            }\n\n            if (\\is_scalar($resolved)) {\n                $this->collectedParameters[$match[1]] = $resolved;\n\n                if (\\is_string($resolved)) {\n                    $resolved = $this->resolve($resolved);\n                }\n\n                if (\\is_scalar($resolved)) {\n                    return false === $resolved ? '0' : (string) $resolved;\n                }\n            }\n\n            throw new RuntimeException(\\sprintf('The container parameter \"%s\", used in the route configuration value \"%s\", must be a string or numeric, but it is of type \"%s\".', $match[1], $value, get_debug_type($resolved)));\n        }, $value);\n\n        return str_replace('%%', '%', $escapedValue);","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/DependencyInjection/Router.php#L163-L199","documentation":"After fetching a container parameter for a route value, the Router checks whether the resolved value itself is (or resolves through) an env var, detected by the internal env_... processor marker pattern. This error means a parameter used in routing indirectly resolves to an env var, which is forbidden because routing is compiled without runtime env access.","triggerScenarios":"A route references %param% where the parameter's value contains or equals a processed env placeholder (matching /env_[a-f0-9]{16}_\\w+_[a-f0-9]{32}/).","commonSituations":"Chained parameters where parameters.yaml defines foo: '%env(BAR)%' and a route uses %foo%; indirection through imported config files.","solutions":["Remove the env indirection: give the parameter a static value in routing context.","Bind the env var to a concrete default via %env(default:...)%% only where runtime resolution is allowed — but not for routing values.","Pass the value as a route default at runtime instead of relying on container compilation."],"exampleFix":"// before (parameters.yaml)\napp_host: '%env(APP_HOST)%'\n// after\napp_host: 'example.com'  # or resolve env outside routing","handlingStrategy":"validation","validationCode":"$v = $container->getParameter($name);\nif (is_string($v) && preg_match('/env_[a-f0-9]{16}_\\w+_[a-f0-9]{32}/Ui', $v)) {\n    throw new LogicException(\"Parameter $name resolves to an env var; not usable in routing.\");\n}","typeGuard":"function isRoutingSafeParam(mixed $v): bool { return !is_string($v) || !preg_match('/env_[a-f0-9]{16}_\\w+_[a-f0-9]{32}/Ui', $v); }","tryCatchPattern":"try { $url = $generator->generate($name); } catch (RuntimeException $e) { // param resolves to env var\n    $logger->error($e->getMessage());\n}","preventionTips":["Avoid parameter chains that end in %env()% for values used by routing","Give such parameters static values or defaults","Inspect resolved parameters with debug:container --parameter"],"tags":["php","symfony-routing","env-vars"],"backgroundTag":"invalid-config-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"}