Skip to content

Commit

Permalink
fixed macro calls on PHP 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 15, 2012
1 parent f48f23a commit be3a5a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
@@ -1,6 +1,6 @@
* 1.10.2 (2012-XX-XX) * 1.10.2 (2012-XX-XX)


* n/a * fixed macro calls on PHP 5.4


* 1.10.1 (2012-10-15) * 1.10.1 (2012-10-15)


Expand Down
4 changes: 3 additions & 1 deletion lib/Twig/Node/Expression/MethodCall.php
Expand Up @@ -10,13 +10,15 @@
*/ */
class Twig_Node_Expression_MethodCall extends Twig_Node_Expression 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); parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno);
} }


public function compile(Twig_Compiler $compiler) public function compile(Twig_Compiler $compiler)
{ {
$this->getNode('node')->setAttribute('always_defined', true);

$compiler $compiler
->subcompile($this->getNode('node')) ->subcompile($this->getNode('node'))
->raw('->') ->raw('->')
Expand Down
8 changes: 7 additions & 1 deletion lib/Twig/Node/Expression/Name.php
Expand Up @@ -19,7 +19,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression


public function __construct($name, $lineno) 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) public function compile(Twig_Compiler $compiler)
Expand All @@ -34,6 +34,12 @@ public function compile(Twig_Compiler $compiler)
} }
} elseif ($this->isSpecial()) { } elseif ($this->isSpecial()) {
$compiler->raw($this->specialVars[$name]); $compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler
->raw('$context[')
->string($name)
->raw(']')
;
} else { } else {
// remove the non-PHP 5.4 version when PHP 5.3 support is dropped // 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 // as the non-optimized version is just a workaround for slow ternary operator
Expand Down

0 comments on commit be3a5a6

Please sign in to comment.