symfony/routing · error · LogicException

Unable to use expressions as the Symfony ExpressionLanguage…

Error message

Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".

What it means

UrlMatcher::getExpressionLanguage() evaluates route condition expressions at match time; it throws this LogicException when the symfony/expression-language class is not installed. Triggered by handleRouteRequirements when a matched route has a condition expression.

Solutions

  1. Run composer require symfony/expression-language
  2. Remove the condition: expression from the route
  3. Replace the condition with a request listener that throws NotFoundHttpException as needed

Example fix

// shell
composer require symfony/expression-language
Defensive patterns

Strategy: fallback

Validate before calling

foreach ($routes->all() as $name => $r) { if ($r->getCondition() && !class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) { trigger_error("Route $name needs symfony/expression-language", E_USER_WARNING); } }

Type guard

function canEvaluateConditions(): bool { return class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class); }

Try / catch

try { $params = $matcher->match($path); } catch (\LogicException $e) { if (str_contains($e->getMessage(), 'ExpressionLanguage component is not installed')) { /* install component or strip conditions */ } throw $e; }

Prevention

When it happens

Trigger: A matched route defines condition: "..." (expression) and the request is matched at runtime while symfony/expression-language is not in vendor/ — e.g. non-optimized (dev) routing without the component.

Common situations: Adding condition: to routes.yaml in a project that never required expression-language; environments where composer installed a subset of packages.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/3596a668270aeb5b. Report an issue: GitHub.

Appendix: source

Thrown at Matcher/UrlMatcher.php:248

    /**
     * Get merged default parameters.
     */
    protected function mergeDefaults(array $params, array $defaults): array
    {
        foreach ($params as $key => $value) {
            if (!\is_int($key) && null !== $value) {
                $defaults[$key] = $value;
            }
        }

        return $defaults;
    }

    protected function getExpressionLanguage(): ExpressionLanguage
    {
        if (!isset($this->expressionLanguage)) {
            if (!class_exists(ExpressionLanguage::class)) {
                throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
            }
            $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
        }

        return $this->expressionLanguage;
    }

    /**
     * @internal
     */
    protected function createRequest(string $pathinfo): ?Request
    {
        if (!class_exists(Request::class)) {
            return null;
        }

        return Request::create($this->context->getScheme().'://'.$this->context->getHost().$this->context->getBaseUrl().$pathinfo, $this->context->getMethod(), $this->context->getParameters(), [], [], [
            'SCRIPT_FILENAME' => $this->context->getBaseUrl(),

View on GitHub (pinned to 83fa223250)