diff --git a/src/Node/Expression/NameExpression.php b/src/Node/Expression/NameExpression.php index 195f64d9edc..c695137458e 100644 --- a/src/Node/Expression/NameExpression.php +++ b/src/Node/Expression/NameExpression.php @@ -60,9 +60,7 @@ public function compile(Compiler $compiler): void ; } else { $compiler - ->raw('(isset($context[') - ->string($name) - ->raw(']) || array_key_exists(') + ->raw('(array_key_exists(') ->string($name) ->raw(', $context) ? $context[') ->string($name) diff --git a/tests/Node/Expression/NameTest.php b/tests/Node/Expression/NameTest.php index 44b5df38733..4593b0b0064 100644 --- a/tests/Node/Expression/NameTest.php +++ b/tests/Node/Expression/NameTest.php @@ -34,7 +34,7 @@ public function getTests() $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"] : throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source))'; + $output = '(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],