Re: Iterator Class/foreach Logic Flaw

From: Date: Thu, 26 Feb 2004 21:43:58 +0000
Subject: Re: Iterator Class/foreach Logic Flaw
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-8190@lists.php.net to get a copy of this message
Marcus Boerger wrote: > As a side note: There is no generally understood hasMore(). I strongly disagree - the Java Iterator has a hasNext() method which is the exact sementic of hasMore(). > Though there > is isDone() and hasMore() is sometimes used/implemented as !isDone(). The > main problem is that the original Iterator description everyone refers to > doesn't have isValid() but instead only has isDone() which doesn't fit > into for(;;). Reference: Gamma et Al, Design Patterns, 1994, Addison > Wesley, p 257ff Hehe - I happen to have the book open on that page:) Fortunately, PHP does not implement GOF patterns wholesale, therefore procedural PHP constructs such as foreach need to deviate from the isDone(). It logically requires an isValid() expression - not a hasMore() or hasNext(). The isValid() iterator method is implemented in the Eclipse project - it gets a mention in dispatches on phppatterns: http://www.phppatterns.com index.php/article/articleview/50/1/1/ (just over half way down). Regards Philip

« previous php.internals (#8190) next »