{
// push all variables into the stack to keep the current state of the parser
$vars = get_object_vars($this);
- unset($vars['stack'], $vars['env']);
+ unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']);
$this->stack[] = $vars;
$this->tmpVarCount = 0;
// tag handlers
- $this->handlers = $this->env->getTokenParsers();
- $this->handlers->setParser($this);
+ if (null === $this->handlers) {
+ $this->handlers = $this->env->getTokenParsers();
+ $this->handlers->setParser($this);
+ }
// node visitors
- $this->visitors = $this->env->getNodeVisitors();
+ if (null === $this->visitors) {
+ $this->visitors = $this->env->getNodeVisitors();
+ }
if (null === $this->expressionParser) {
$this->expressionParser = new Twig_ExpressionParser($this, $this->env->getUnaryOperators(), $this->env->getBinaryOperators());