diff --git a/src/Node/Expression/NameExpression.php b/src/Node/Expression/NameExpression.php index f52513427..195f64d9e 100644 --- a/src/Node/Expression/NameExpression.php +++ b/src/Node/Expression/NameExpression.php @@ -66,11 +66,11 @@ class NameExpression extends AbstractExpression ->string($name) ->raw(', $context) ? $context[') ->string($name) - ->raw('] : (function () { throw new RuntimeError(\'Variable ') + ->raw('] : throw new RuntimeError(\'Variable ') ->string($name) ->raw(' does not exist.\', ') ->repr($this->lineno) - ->raw(', $this->source); })()') + ->raw(', $this->source)') ->raw(')') ; } diff --git a/tests/Node/Expression/NameTest.php b/tests/Node/Expression/NameTest.php index 57ba02b76..44b5df387 100644 --- a/tests/Node/Expression/NameTest.php +++ b/tests/Node/Expression/NameTest.php @@ -34,7 +34,7 @@ class NameTest extends NodeTestCase $env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]); $env1 = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => false]); - $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : (function () { throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source); })())'; + $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source))'; return [ [$node, "// line 1\n".$output, $env],