{"record":{"id":"819a121d69f9e316","repo":"symfony/http-kernel","slug":"unable-to-use-expressions-as-the-symfony-expressionlanguage","errorCode":null,"errorMessage":"Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running \"composer require symfony/expression-language\".","messagePattern":"Unable to use expressions as the Symfony ExpressionLanguage component is not installed\\. Try running \"composer require symfony/expression-language\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"EventListener/CacheAttributeListener.php","lineNumber":285,"sourceCode":"    }\n\n    /**\n     * @param-immediately-invoked-callable $closureOrExpression\n     */\n    private function evaluate(string|Expression|\\Closure $closureOrExpression, array $variables): mixed\n    {\n        if ($closureOrExpression instanceof \\Closure) {\n            return $closureOrExpression($variables['args'], $variables['request'], $variables['this']);\n        }\n\n        return $this->getExpressionLanguage()->evaluate($closureOrExpression, $variables);\n    }\n\n    private function getExpressionLanguage(): ExpressionLanguage\n    {\n        return $this->expressionLanguage ??= class_exists(ExpressionLanguage::class)\n            ? new ExpressionLanguage()\n            : throw new \\LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running \"composer require symfony/expression-language\".');\n    }\n\n    private function toSeconds(int|string $time): int\n    {\n        if (!is_numeric($time)) {\n            $now = time();\n            $time = strtotime($time, $now) - $now;\n        }\n\n        return $time;\n    }\n}\n","sourceCodeStart":267,"sourceCodeEnd":298,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/EventListener/CacheAttributeListener.php#L267-L298","documentation":"CacheAttributeListener::getExpressionLanguage() lazily creates an ExpressionLanguage to evaluate attribute expressions. If the symfony/expression-language package is absent (class does not exist), it throws a LogicException telling the developer to install the component.","triggerScenarios":"Dispatching a request to a controller with #[Cache(if: 'expression')] (or variables needing evaluation) when symfony/expression-language is not installed via Composer.","commonSituations":"Production builds pruning dev dependencies where expression-language is only in require-dev; new project forgetting the package while using cache attributes; framework upgrade introducing expression-based attribute options.","solutions":["Run \"composer require symfony/expression-language\".","Remove expression strings from Cache attributes so no ExpressionLanguage is needed.","Ensure the package is in the 'require' (not require-dev) section of composer.json for production use."],"exampleFix":"// before (composer.json)\n\"require-dev\": { \"symfony/expression-language\": \"^7.0\" }\n// after\n\"require\": { \"symfony/expression-language\": \"^7.0\" }","handlingStrategy":"validation","validationCode":"if (!class_exists(\\Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::class)) { throw new \\RuntimeException('symfony/expression-language is required for Cache expressions'); }","typeGuard":null,"tryCatchPattern":"try { $response = $controller(); } catch (\\LogicException $e) { if (str_contains($e->getMessage(), 'ExpressionLanguage')) { /* install package or bypass attribute */ } throw $e; }","preventionTips":["Add symfony/expression-language to composer require when using Cache attributes","Run composer install --no-dev checks in CI to catch pruned packages","Keep attribute expressions optional with boolean literals in environments lacking the package"],"tags":["missing-package","composer","expression-language","symfony"],"backgroundTag":"missing-optional-dependency","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}