Re: Iterators?
| From: | Alan Knowles | Date: | Mon, 23 Jun 2003 00:41:27 +0000 |
| Subject: | Re: Iterators? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-17629@lists.php.net to get a copy of this message | ||
Harry Fuecks wrote:
In case anyone is wondering, took my shot at explaining Iterators here: http://www.phppatterns.com/index.php/article/articleview/50/1/1/Site was down at the moment.. - considering the example below, It's pretty clear that classic iterators are not that usefull. as they are provided by the language. It would be vaugely useful to define Iterator (and a few other) 'interfaces' as abstract standards - for PHP5. eg. abstract class Interfaces_Iterator { abstract function next(); ..... } Downside is that it does add an extra dependancy with no real 'runtime' value.. - I guess in PHP5 we could do something like.. function __autoload($x) { if ($in_production && substr($x,0,8) == 'Interface') { class $x extends StdClass {} return; } .. otherwise load the interface... } Regards Alan
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...-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com