From 75b7421e8372e15f94ea4a791bb038e5bdd8594f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 28 Dec 2020 11:45:58 +0100 Subject: [PATCH] Remove usage of isset before array_key_exists as performance is not an issue anymore --- src/Node/Expression/NameExpression.php | 4 +--- tests/Node/Expression/NameTest.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) 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],