Re: Iterator Class/foreach Logic Flaw?

From: Date: Thu, 26 Feb 2004 19:58:49 +0000
Subject: Re: Iterator Class/foreach Logic Flaw?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-8184@lists.php.net to get a copy of this message
Thanks Marcus Looking at the documentation, the comments and method name (for hasMore()) do not have the same meaning - the comment is saying 'does the current element exist?' and the method name says 'are there any more elements?'. This makes the api very ambiguous - hasMore() and isValid() have very specific meaning in many languages wrt iterators. Whilst I appreciate adding an isValid() method to the Iterator interface is not trivial (and I am loath to suggest a change this close to PHP RC phase), but it is surely better to have an un-ambiguous api on release - especially after all the clamouring for an interface implementation :) Regards Philip Marcus Boerger wrote: > 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 >

« previous php.internals (#8184) next »