Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:8190 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99950 invoked by uid 1010); 26 Feb 2004 21:52:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 99926 invoked by uid 1007); 26 Feb 2004 21:52:44 -0000 Message-ID: <20040226215244.99924.qmail@pb1.pair.com> To: internals@lists.php.net Mail-Copies-To: philip@stutchbury.com Date: Thu, 26 Feb 2004 21:43:58 +0000 References: <20040226160254.4324.qmail@pb1.pair.com> <1051368455281.20040226204516@marcus-boerger.de> <20040226200755.99362.qmail@pb1.pair.com> <20040226205225.87119.qmail@pb1.pair.com> <751373122906.20040226220304@marcus-boerger.de> <20040226211355.32213.qmail@pb1.pair.com> <81374335265.20040226222316@marcus-boerger.de> Lines: 28 Organization: Stutchbury User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Posted-By: 62.49.23.238 Subject: Re: [PHP-DEV] Iterator Class/foreach Logic Flaw From: philip@stutchbury.com (Philip Fletcher) 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