Iterators?

From: Date: Sun, 22 Jun 2003 23:40:42 +0000
Subject: Iterators?
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-17628@lists.php.net to get a copy of this message
Wondering what the general feeling is about PEAR providing some standard iterators? I know that there's a resistance to dependancies between packages but iterators (even if it's just PHP's foreach) are so common in PHP that having standard ones available in PEAR could add alot of value. While working on XML_SaxFilters (http://marc.theaimsgroup.com/?l=pear- dev&m=105631965923509&w=2) for example I had to write my own simple iterator for reading data (the ReaderInterface). Ideally I would have liked to use a PEAR iterator package if one existed. Other packages, like HTML_Table for example, might also benefit from iterators; you could have an iterator for PEAR::DB result objects which could be used as the data source for HTML_Table. HTML_Table could then iterate over the results automatically. Code wise there's at least 5 different types of iterator I've seen, written in PHP, the more complex ones keeping an index internally while simpler ones work rely on the sequences PHP provides at an "engine level". Between them there's probably a plenty of code to base iterators on for use in PEAR. In case anyone is wondering, took my shot at explaining Iterators here: http://www.phppatterns.com/index.php/article/articleview/50/1/1/ On a side note, seems Java is borrowing from PHP's foreach{} (OK - no proof that they got the idea from PHP but interesting anyway). There's an interesting interview (http://java.sun.com/features/2003/05/bloch_qa.html) about Java 1.5. The queston about "enhanced for"... The old Java way; void cancelAll(Collection c) { for (Iterator i = c.iterator(); i.hasNext(); ) {
       TimerTask tt = (TimerTask) i.next();
       tt.cancel();
} } With 1.5 Java way; void cancelAll(Collection c) { for (Object o : c)
       ((TimerTask)o).cancel();
} Looks like a foreach...

« previous php.pear.dev (#17628) next »