Wednesday, February 23, 2011

Unset problem with Collection implements Countable, Iterator, ArrayAccess

I just have one problem with my Collection class implements Countable, Iterator, ArrayAccess. Let's look at the code below:

foreach ($Collection as $index => $model) {
//do something
unset($Collection[$index]);
}

But, obviously, I haven't found any solution to make the above code work properly. It is all about the array internal pointer, the valid() method and the offsetUnset() method. I tried different with my own implementation and with others' code(code searched from google, and code implemented by some open source software like tomatocms)

No comments: