symfony/routing · error · RuntimeException
The container parameter
Error message
The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".
What it means
Route configuration values are built from container parameters; every matched %param% must resolve to a string or scalar so it can be cast. This error means the parameter resolved to a non-scalar type (array, null, object) and cannot be embedded in the route configuration string.
Solutions
- Change the parameter to a scalar (string/int/bool) value in your config.
- Reference a specific scalar element of the array parameter instead of the whole array.
- Check config parsing: YAML values like 'key: [a, b]' become arrays; quote or restructure them.
Example fix
// before (config.yaml) parameters: app_hosts: ['a.com', 'b.com'] # routes.yaml: host: '%app_hosts%' // after parameters: app_host: 'a.com' # routes.yaml: host: '%app_host%'
Defensive patterns
Strategy: type-guard
Validate before calling
$v = $container->getParameter($name);
if (!is_scalar($v) && null !== $v) {
throw new LogicException("Parameter $name must be scalar for routing use.");
} Type guard
function isScalarParam(mixed $v): bool { return is_scalar($v) || null === $v; } Try / catch
try { $url = $generator->generate($name, $params); } catch (RuntimeException $e) { // non-scalar parameter in route config
$logger->error($e->getMessage());
} Prevention
- Keep routing-referenced parameters scalar
- Check YAML types (lists/quotes) for parameters used in routes
- Cast explicitly when defining parameters programmatically
When it happens
Trigger: Router::resolve finds %param% in a route value, paramFetcher returns an array/null/resource, and get_debug_type reports a non-scalar type.
Common situations: Defining a route default or host as an array parameter in config; a YAML parameter parsed as a list; a null parameter after failed env resolution.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Using "%% %%" is not allowed in routing configuration.
- The container parameter
- Unable to generate a URL for the named route
- Target route " " for alias " " does not exist.
- Unable to generate a URL for the named route
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/bb662d7bc77ef3fd.
Report an issue: GitHub.
Appendix: source
Thrown at DependencyInjection/Router.php:196
$resolved = ($this->paramFetcher)($match[1]);
if (\is_string($resolved) && preg_match('/env_[a-f0-9]{16}_\w+_[a-f0-9]{32}/Ui', $resolved)) {
throw new RuntimeException(\sprintf('The container parameter "%s" resolves to an env var, which is not allowed in routing configuration.', $match[1]));
}
if (\is_scalar($resolved)) {
$this->collectedParameters[$match[1]] = $resolved;
if (\is_string($resolved)) {
$resolved = $this->resolve($resolved);
}
if (\is_scalar($resolved)) {
return false === $resolved ? '0' : (string) $resolved;
}
}
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)));
}, $value);
return str_replace('%%', '%', $escapedValue);
}
public static function getSubscribedServices(): array
{
return [
'routing.loader' => LoaderInterface::class,
];
}
}
View on GitHub (pinned to 83fa223250)