FWIW I wrote a patch for this out of curiosity.

Rather than relying on _iterationPointerValid, it simply uses an index pointer - if the index is equal to the length of the array length then 'valid()' will always return false. rewind() will reset this pointer to 0.

If you find it useful I'll add it to the Bug tracker

Cheers

===================================================================
--- Config.php  (revision 1090)
+++ Config.php  (working copy)
@@ -35,7 +35,7 @@
class Zend_Config implements Countable, Iterator
{
     protected $_allowModifications;
-    protected $_iterationPointerValid;
+    protected $_index = 0;
     protected $_data;
     /**
@@ -179,21 +179,18 @@
      */
     public function next()
     {
-        if (next($this->_data) === false) {
-            $this->_iterationPointerValid = false;
-        } else {
-            $this->_iterationPointerValid = true;
-        }
+        next($this->_data);
+        $this->_index++;
     }
     /**
      * Defined by Iterator interface
      *
      */
-    public function rewind ()
+    public function rewind()
     {
         reset($this->_data);
-        $this->_iterationPointerValid = true;
+        $this->_index = 0;
     }
     /**
@@ -201,9 +198,9 @@
      *
      * @return boolean
      */
-    public function valid ()
+    public function valid()
     {
-        return $this->_iterationPointerValid;
+        return ($this->_index < count($this->_data));
     }
}


next() should not return the value, ever. This is not an issue.

Iteration works like thus:

next() - moves pointer one place forward (doesn't care if it's valid or not)
valid() - checks pointer is in a valid place (here's where we check that, returns boolean)
current() - returns current value

So the next() method below is doing more than it should - it should only advance the pointer.

- Davey


--

Simon Mundy | Director | PEPTOLAB

""" " "" """""" "" "" """"""" " "" """"" " """"" "  """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124


Reply via email to