{"record":{"id":"fdfd69a6e57e5c90","repo":"symfony/http-kernel","slug":"cannot-evaluate-expression-for-controllers-since-no","errorCode":null,"errorMessage":"Cannot evaluate Expression for controllers since no ExpressionLanguage service was configured.","messagePattern":"Cannot evaluate Expression for controllers since no ExpressionLanguage service was configured\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"Event/ControllerEvent.php","lineNumber":147,"sourceCode":"    public function evaluate(mixed $value, ?ExpressionLanguage $expressionLanguage, array $args = []): mixed\n    {\n        if (!$value instanceof \\Closure && !$value instanceof Expression) {\n            return $value;\n        }\n\n        $controller = $this->getController();\n        $controller = match (true) {\n            \\is_object($controller) && !$controller instanceof \\Closure => $controller,\n            \\is_array($controller) && \\is_object($controller[0]) => $controller[0],\n            default => null,\n        };\n\n        if ($value instanceof \\Closure) {\n            return $value($args, $this->getRequest(), $controller);\n        }\n\n        if (!$expressionLanguage) {\n            throw new \\LogicException('Cannot evaluate Expression for controllers since no ExpressionLanguage service was configured.');\n        }\n\n        return $expressionLanguage->evaluate($value, [\n            'request' => $this->getRequest(),\n            'args' => $args,\n            'this' => $controller,\n        ]);\n    }\n}\n","sourceCodeStart":129,"sourceCodeEnd":157,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Event/ControllerEvent.php#L129-L157","documentation":"ControllerEvent::evaluate() evaluates a controller-reference expression for a #[Cache]/expression-driven attribute. When the expression value is not a Closure, an ExpressionLanguage instance is required to evaluate it; if none was configured (null), the method refuses with a LogicException instead of fataling on a null call.","triggerScenarios":"Calling ControllerEvent->evaluate() with a string expression (or an attribute whose value is a plain string) while the listener was constructed without an ExpressionLanguage, e.g. when the symfony/expression-language package is not installed or not wired into the listener.","commonSituations":"Using #[AsController]/expression-based attributes in a project missing symfony/expression-language; running unit tests that build the listener without passing the ExpressionLanguage argument; kernel not registering the 'expression_language' service.","solutions":["Run \"composer require symfony/expression-language\" and clear the cache so the ExpressionLanguage service is registered.","Pass an ExpressionLanguage instance when constructing the listener/ControllerEvent in tests.","Replace the string expression with a Closure, which is evaluated without ExpressionLanguage."],"exampleFix":"// before\n$event->evaluate('request.getMethod() == \"POST\"');\n// after\n$event->evaluate(fn ($args, $request) => $request->getMethod() === 'POST');","handlingStrategy":"fallback","validationCode":"// before calling evaluate\nif (!is_string($value) || !class_exists(\\Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::class)) { /* use a closure instead */ }","typeGuard":"$canEvaluate = fn($v): bool => $v instanceof \\Closure || class_exists(\\Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::class);","tryCatchPattern":"try { $result = $event->evaluate($expr); } catch (\\LogicException $e) { $result = $closureFallback($args, $request); }","preventionTips":["Require symfony/expression-language whenever expression-based attributes are used","Prefer Closures over string expressions in application code","In tests, always wire an ExpressionLanguage into the listener"],"tags":["expression-language","missing-dependency","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"}