I've got this notice:
ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in /var/www...
which is produced by this code, at the begining of the foreach loop. Together with the notice, the foreach loop starts iterating all over again. In other words, the internal position is reset whenever this thing happens. But acording to php manual, ArrayObject is using ArrayIterator by default.
And manual says this about ArrayIterator
This iterator allows to unset and modify values and keys while iterating over Arrays and Objects.
Am I missing something here? I found some bugreports about ArratIterator, but not this kind. Is it a bug or is it my bad?
version: PHP Version 5.3.10-1ubuntu3.4
<?php
//file 1:
// no namespace
abstract class holder extends \ArrayObject{
// abstract function init();
public function __construct($init){
parent::__construct($init, 1);
}
}?>
<?php
//file 2:
namespace troops;
class holder extends \holder{
public function __construct(){
parent::__construct($this->init());
}
private function init(){
return array( /*... some data from db ...*/ );
}
public function saveData(){
foreach($this as $k => $v){
$this->save($v);
if($v->number_of_items==0) {
unset($k);
// $this->offsetUnset($k); // tryed both
}
}
}
}
?>