fixed iterator_to_array() usage (closes #57)
authorFabien Potencier <fabien.potencier@gmail.com>
Thu, 27 May 2010 16:42:40 +0000 (18:42 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Thu, 27 May 2010 16:42:51 +0000 (18:42 +0200)
CHANGELOG
lib/Twig/Extension/Core.php
lib/Twig/Node/For.php

index 225ca4e..d5adc45 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@
 Backward incompatibilities:
  * The short notation of the `block` tag changed.
 
+ * fixed iterator_to_array() usage
  * changed the date filter to support any date format supported by DateTime
  * added ignore_invalid_variables setting to throw an exception when an invalid variable is used in a template (disabled automatically when debug is true)
  * added the lexer, parser, and compiler as arguments to the Twig_Environment constructor
index be92d94..241614e 100644 (file)
@@ -185,7 +185,7 @@ function twig_in_filter($value, $compare)
     } elseif (is_string($compare)) {
         return false !== strpos($compare, (string) $value);
     } elseif (is_object($compare) && $compare instanceof Traversable) {
-        return in_array($value, iterator_to_array($compare));
+        return in_array($value, iterator_to_array($compare, false));
     }
 
     return false;
@@ -298,12 +298,12 @@ else
     }
 }
 
-function twig_iterator_to_array($seq)
+function twig_iterator_to_array($seq, $useKeys = true)
 {
     if (is_array($seq)) {
         return $seq;
     } elseif (is_object($seq) && $seq instanceof Traversable) {
-        return $seq instanceof Countable ? $seq : iterator_to_array($seq);
+        return $seq instanceof Countable ? $seq : iterator_to_array($seq, $useKeys);
     } else {
         return array();
     }
index f7541ce..761de92 100644 (file)
@@ -69,7 +69,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface
         $compiler
             ->write("\$context['_seq'] = twig_iterator_to_array(")
             ->subcompile($this->seq)
-            ->raw(");\n")
+            ->raw(", ".($this->isMultitarget ? 'true' : 'false').");\n")
         ;
 
         if ($this->withLoop) {