Skip to content

Commit

Permalink
optimized context access on PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 26, 2019
1 parent bf3781c commit cae5952
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* 1.40.0 (2019-XX-XX)

* optimized context access on PHP 7.4
* allowed Twig\NodeVisitor\NodeVisitorInterface::leaveNode() to return "null" instead of "false" (same meaning)
* added the "apply" tag as a replacement for the "filter" tag
* allowed Twig\Loader\FilesystemLoader::findTemplate() to return "null" instead of "false" (same meaning)
Expand Down
9 changes: 8 additions & 1 deletion src/Node/Expression/NameExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ public function compile(Compiler $compiler)
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} elseif (\PHP_VERSION_ID >= 700400) {
$compiler
->raw('array_key_exists(')
->string($name)
->raw(', $context)')
;
} else {
$compiler
->raw('(isset($context[')
->string($name)
->raw(']) || array_key_exists(')
->string($name)
->raw(', $context))');
->raw(', $context))')
;
}
} elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]);
Expand Down

0 comments on commit cae5952

Please sign in to comment.