Hello Philip, have a look at it's dokumentation: ext/spl/spl.php there you'll find that hasMore() needs to be checked before an access to key() or current() can be done. Hence it's meaning is somewhat like isValid().
regards marcus Thursday, February 26, 2004, 4:53:50 PM, you wrote: > At the risk of making a complete fool of myself, I'd like to ask the smarter > brains than me to checkout the current logic in the implementation of > Iterator classes and foreach(). > The current logic of foreach( $obj as $key => $val ) { ... } where $obj > implements Iterator, is: > for($obj->rewind(); $obj->hasMore(); $obj->next() ) { ... } > but it should be: > for($obj->rewind(); $obj->isValid(); $obj->next() ) { ... } > As the iterator exits the penultimate interation, next() is called, placing > the 'pointer' on the last 'record'. But before the last record is > processed, hasMore() is called, which *should* return FALSE, because we > have already moved to the last record. > The implementations I have seen so far all return TRUE from hasMore() when > positioned (i.e. current()) on the last record - this is not logical > (Captain). It also prevents proper use of a class implementing an iterator > outside of the foreach construct. > Philip -- Best regards, Marcus mailto:[EMAIL PROTECTED] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php