In a new post to his blog today Sean Coates talks about some of his work with Iterators in PHP and how, despite a bad example in the manual, he solved his issue (and updated the PHP manual too).
In the back end, we have models that connect to CouchDB. These models implement the Iterator pattern to allow easy traversal of a recordâ€™s keys. [...] Little did I realize that this implementation is very broken. [...] Over the past few years, Iâ€™ve implemented many iterators in this way, using PHPâ€™s implicit array manipulation functions (reset(), current(), key(), next()).He points out some issues with how PHP handles array index tracking and how, in the previous PHP manual example, it incorrectly checked for "false" against the current array value. His updated version doesn't have this issue. You can see it here.