Skip to content
Browse files

fixed macro calls on PHP 5.4

  • Loading branch information...
1 parent f48f23a commit be3a5a6421b30ad708d1e50c3aca463e7227cdf9 @fabpot committed
Showing with 11 additions and 3 deletions.
  1. +1 −1 CHANGELOG
  2. +3 −1 lib/Twig/Node/Expression/MethodCall.php
  3. +7 −1 lib/Twig/Node/Expression/Name.php
View
2 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)
View
4 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('->')
View
8 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

0 comments on commit be3a5a6

Please sign in to comment.
Something went wrong with that request. Please try again.