The initialization of object is in loop of tests, because
this object is initialized only when used.
But in real context we don't have a loop on same object "Zend_Config".

So for me it's a usage problem but it's interesting to add a warning
in documentation mostly if Zend_Config it's not alone class in this case.

Posted by julien PAULI (doctorrock83) on 2009-06-15T09:25:43.000+0000

Ok I see.

toArray() works directly on the _data array, and so does the iterator.
When calling toArray(), a foreach loop is used to iterate throught _data, that foreach loop first calls rewind() internaly , and then iterates. The problem is that the foreach loop leaves the array iterator at an undefinied position (that's why rewind() is called by foreach before the iteration).
Then when you call current() on your object, it just says it doesn't have a current value.

$config = new Zend_Config(array(1,2,3));
$config->rewind(); // rewound
$config->toArray(); // the internal iterator is somewhere after the last position due to foreach loop
assert($config->current() == false); // OK

To see that, create a getIndex() method in Zend_Config, which return $_index; and try this :

$config = new Zend_Config(array(1,2,3));
$config->rewind(); // rewound
$config->toArray(); // the internal iterator is somewhere after the last position due to foreach loop
assert($config->key() == $config->getIndex()); // WRONG , $config->key() returns NULL while getIndex() has the right value

The patch is easy, trigger the internal PHP copy-on-write system to make foreach loop over a copy of the _data array, and not the real _data.
Just add :