symfony/routing · error · LogicException
You should either pass a
Error message
You should either pass a "%s" instance or provide the $parameters argument of the "%s" method.
What it means
DependencyInjection\Router needs a way to fetch route parameters: either a Psr\Container\ContainerInterface (whose $parameters is a ContainerParamFetcher-like object exposing get()) or a Symfony ContainerInterface to read parameters via getParameter(). If the $container passed is neither, a LogicException is thrown instructing to pass a PSR-11 container or provide $parameters.
Solutions
- Pass a Psr\Container\ContainerInterface instance (or Symfony Container) as the first constructor argument
- Provide the $parameters argument explicitly (a callable/fetcher with get()) instead of relying on the container
- Use the framework's dependency-injected router service rather than instantiating it manually
Example fix
// before $router = new Router($somePlainObject, $loader, $routes); // after $router = new Router($container, $loader, $routes, [], null, null, $parameters: $container);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!$container instanceof \Psr\Container\ContainerInterface && !$container instanceof \Symfony\Component\DependencyInjection\ContainerInterface && null === $parameters) {
throw new \LogicException('Provide a PSR-11/Symfony container or a $parameters argument');
} Type guard
function isRouterContainer(mixed $c): bool {
return $c instanceof \Psr\Container\ContainerInterface
|| $c instanceof \Symfony\Component\DependencyInjection\ContainerInterface;
} Try / catch
try {
$router = new \Symfony\Component\Routing\DependencyInjection\Router($container, $loader, $routes);
} catch (\LogicException $e) {
// retry passing an explicit $parameters fetcher
} Prevention
- Instantiate the DI Router only with a real PSR-11 or Symfony container
- Use the container-built router service instead of manual construction
- Match the constructor signature of your installed Symfony version (>=6.1 supports $parameters)
When it happens
Trigger: new Router($containerThatIsNotPsr11NorSymfonyContainer, $loader, $routes, ...) where $parameters is null and the container doesn't implement Symfony's ContainerInterface (e.g. a custom PSR-11 wrapper without the Psr\Container\ContainerInterface type, wrong container passed, or null container).
Common situations: Constructing the DI Router manually in tests or standalone apps with a homemade container; passing a PSR-11-only container that isn't Symfony's (note it must implement Psr\Container\ContainerInterface to satisfy $parameters->get), version differences after the $parameters argument was added in Symfony 6.1.
Related errors
- Case must be a "BackedEnum" instance
- " :: " is not a case of " ".
- Route alias " " can not reference itself.
- The router " " cannot be warmed up because it does not…
- Cannot unserialize Symfony\Component\Routing\CompiledRoute
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/5a4e800f88ddcaf5.
Report an issue: GitHub.
Appendix: source
Thrown at DependencyInjection/Router.php:64
private ContainerInterface $container,
mixed $resource,
array $options = [],
?RequestContext $context = null,
?ContainerInterface $parameters = null,
?LoggerInterface $logger = null,
?string $defaultLocale = null,
) {
$this->resource = $resource;
$this->context = $context ?? new RequestContext();
$this->logger = $logger;
$this->setOptions($options);
if ($parameters) {
$this->paramFetcher = $parameters->get(...);
} elseif ($container instanceof SymfonyContainerInterface) {
$this->paramFetcher = $container->getParameter(...);
} else {
throw new \LogicException(\sprintf('You should either pass a "%s" instance or provide the $parameters argument of the "%s" method.', SymfonyContainerInterface::class, __METHOD__));
}
$this->defaultLocale = $defaultLocale;
}
public function getRouteCollection(): RouteCollection
{
if (!isset($this->collection)) {
$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
$this->resolveParameters($this->collection);
$this->collection->addResource(new ContainerParametersResource($this->collectedParameters));
try {
$containerFile = ($this->paramFetcher)('kernel.build_dir').'/'.($this->paramFetcher)('kernel.container_class').'.php';
if (file_exists($containerFile)) {
$this->collection->addResource(new FileResource($containerFile));
} else {
$this->collection->addResource(new FileExistenceResource($containerFile));View on GitHub (pinned to 83fa223250)