mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 03:46:39 +00:00
Don't unset loop when it's not defined
This commit is contained in:
@@ -79,7 +79,7 @@ class ForNode extends Node
|
||||
}
|
||||
|
||||
// remove some "private" loop variables (needed for nested loops)
|
||||
$compiler->write('unset($context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'loop\']);'."\n");
|
||||
$compiler->write('unset($context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\']'.($this->getAttribute('with_loop') ? ', $context[\'loop\']' : '').");\n");
|
||||
|
||||
// keep the values set in the inner context for variables defined in the outer context
|
||||
$compiler->write("\$context = array_intersect_key(\$context, \$$parentVar) + \$$parentVar;\n");
|
||||
|
||||
@@ -63,7 +63,7 @@ class ForTest extends NodeTestCase
|
||||
foreach (\$__internal_compile_0 as \$context["key"] => \$context["item"]) {
|
||||
yield {$this->getVariableGetter('foo')};
|
||||
}
|
||||
unset(\$context['key'], \$context['item'], \$context['loop']);
|
||||
unset(\$context['key'], \$context['item']);
|
||||
\$context = array_intersect_key(\$context, \$__internal_compile_2) + \$__internal_compile_2;
|
||||
return; yield;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user