diff --git a/Compiler.php b/Compiler.php index 9228734..7b8be11 100644 --- a/Compiler.php +++ b/Compiler.php @@ -200,6 +200,13 @@ class Compiler */ private $_level; + /** + * Contains the current iterator ID to avoid name collisions. + * + * @var int + */ + private $_iteratorId; + /** * Creates a new compiler instance. * @@ -441,6 +448,7 @@ public function compile($input, $path = null) $this->_calledMixins = []; $this->_blocks = []; $this->_level = 0; + $this->_iteratorId = 0; //Parse the input into an AST $node = null; @@ -1322,12 +1330,12 @@ protected function compileMixins() if ($variadicIndex !== null) { - $args[$variadicName] = "array_slice(\$__arguments, $variadicIndex);"; + $args[$variadicName] = "array_slice(\$__arguments, $variadicIndex)"; } $phtml .= $this->createCode( '$__mixins[\''.$name.'\'] = function(array $__arguments) use($__args, $__mixins) { - static $__defaults = '.$this->exportArray($args).'; + $__defaults = '.$this->exportArray($args).'; $__arguments = array_replace($__defaults, $__arguments); $__args = array_replace($__args, $__arguments); extract($__args); @@ -1613,8 +1621,6 @@ protected function compileWhen(Node $node) protected function compileEach(Node $node) { - static $id = 0; - $subject = $node->subject; if ($this->isVariable($subject)) @@ -1625,7 +1631,7 @@ protected function compileEach(Node $node) if ($node->keyName) $as = "\${$node->keyName} => ".$as; - $var = '$__iterator'.($id++); + $var = '$__iterator'.($this->_iteratorId++); $phtml = $this->createCode("$var = {$subject};").$this->newLine(); $phtml .= $this->indent().$this->createCode("foreach ($var as $as) {").$this->newLine(); $phtml .= $this->compileChildren($node->children).$this->newLine(); diff --git a/Test/MixinTest.php b/Test/MixinTest.php index 8699b84..9101e99 100644 --- a/Test/MixinTest.php +++ b/Test/MixinTest.php @@ -14,9 +14,7 @@ public function setUp() { $this->_renderer = new Renderer([ - 'adapterOptions' => [ - 'path' => __DIR__.'/cache/mixins' - ], + 'cachePath' => __DIR__.'/cache/mixins', 'pretty' => false, 'paths' => [__DIR__.'/views/mixins'] ]); @@ -63,4 +61,19 @@ public function testIdAndClassForwarding() 'id-and-class-forwarding' )); } + + public function testVariadic() + { + + $this->assertEquals('