From be3a5a6421b30ad708d1e50c3aca463e7227cdf9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 15 Oct 2012 10:22:12 +0200 Subject: [PATCH] fixed macro calls on PHP 5.4 --- CHANGELOG | 2 +- lib/Twig/Node/Expression/MethodCall.php | 4 +++- lib/Twig/Node/Expression/Name.php | 8 +++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 447363dee3..18d428ad79 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.10.2 (2012-XX-XX) - * n/a + * fixed macro calls on PHP 5.4 * 1.10.1 (2012-10-15) diff --git a/lib/Twig/Node/Expression/MethodCall.php b/lib/Twig/Node/Expression/MethodCall.php index 50938084b5..2c24c2cda8 100644 --- a/lib/Twig/Node/Expression/MethodCall.php +++ b/lib/Twig/Node/Expression/MethodCall.php @@ -10,13 +10,15 @@ */ class Twig_Node_Expression_MethodCall extends Twig_Node_Expression { - public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno) + public function __construct(Twig_Node_Expression_Name $node, $method, Twig_Node_Expression_Array $arguments, $lineno) { parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno); } public function compile(Twig_Compiler $compiler) { + $this->getNode('node')->setAttribute('always_defined', true); + $compiler ->subcompile($this->getNode('node')) ->raw('->') diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 8f5a1ea808..2e5321d323 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -19,7 +19,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression public function __construct($name, $lineno) { - parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false), $lineno); + parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false), $lineno); } public function compile(Twig_Compiler $compiler) @@ -34,6 +34,12 @@ public function compile(Twig_Compiler $compiler) } } elseif ($this->isSpecial()) { $compiler->raw($this->specialVars[$name]); + } elseif ($this->getAttribute('always_defined')) { + $compiler + ->raw('$context[') + ->string($name) + ->raw(']') + ; } else { // remove the non-PHP 5.4 version when PHP 5.3 support is dropped // as the non-optimized version is just a workaround for slow ternary operator