fixed macro compilation when a variable name is a PHP reserved keyword (closes #881)

This commit is contained in:
Fabien Potencier
2012-11-05 08:50:56 +01:00
parent a009821dd3
commit abec35b833
4 changed files with 19 additions and 4 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.11.0 (2012-XX-XX)
* fixed macro compilation when a variable name is a PHP reserved keyword
* changed the date filter behavior to always apply the default timezone, except if false is passed as the timezone
* fixed bitwise operator precedences
* added the template_from_string function
+2 -2
View File
@@ -31,7 +31,7 @@ class Twig_Node_Macro extends Twig_Node
{
$arguments = array();
foreach ($this->getNode('arguments') as $argument) {
$arguments[] = '$'.$argument->getAttribute('name').' = null';
$arguments[] = '$_'.$argument->getAttribute('name').' = null';
}
$compiler
@@ -52,7 +52,7 @@ class Twig_Node_Macro extends Twig_Node
$compiler
->write('')
->string($argument->getAttribute('name'))
->raw(' => $'.$argument->getAttribute('name'))
->raw(' => $_'.$argument->getAttribute('name'))
->raw(",\n")
;
}
@@ -0,0 +1,14 @@
--TEST--
macro
--TEMPLATE--
{% from _self import test %}
{% macro test(this) -%}
{{ this }}
{%- endmacro %}
{{ test(this) }}
--DATA--
return array('this' => 'foo');
--EXPECT--
foo
+2 -2
View File
@@ -43,10 +43,10 @@ class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
return array(
array($node, <<<EOF
// line 1
public function getfoo(\$foo = null)
public function getfoo(\$_foo = null)
{
\$context = \$this->env->mergeGlobals(array(
"foo" => \$foo,
"foo" => \$_foo,
));
\$blocks = array();