Nesting the same template inside a `foreach` loop that is also accessed inside the nested call will overwrite the values from the outer template due to identical identifiers being used.
The sandbox did not protected `$this->foreachVars` despite being stateful.
See #4431
Fixes #4444
public function enableSandbox()
{
$index = \count($this->sandboxVars);
- $this->sandboxVars[$index] = $this->v;
+ $this->sandboxVars[$index] = [
+ 'foreachVars' => $this->foreachVars,
+ 'v' => $this->v,
+ ];
}
/**
throw new SystemException('TemplateEngine is currently not running in a sandbox.');
}
- $this->v = \array_pop($this->sandboxVars);
+ $values = \array_pop($this->sandboxVars);
+ $this->foreachVars = $values['foreachVars'];
+ $this->v = $values['v'];
}
/**