From: Fabien Potencier Date: Mon, 15 Oct 2012 08:22:12 +0000 (+0200) Subject: fixed macro calls on PHP 5.4 X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=be3a5a6421b30ad708d1e50c3aca463e7227cdf9;p=web%2Fkonrad%2Ftwig.git fixed macro calls on PHP 5.4 --- diff --git a/CHANGELOG b/CHANGELOG index 447363d..18d428a 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 5093808..2c24c2c 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 8f5a1ea..2e5321d 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 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression } } 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