[PHP-DEV] Re: Cannot use foreach() with $this->my_iterator within a class

2004-03-02 Thread Philip Fletcher
Please ignore - this has been fixed somewhere between php5-200402260830 and php5-200403022230. Philip -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Re: Iterator Class/foreach Logic Flaw? (was: [PHP-DEV] Cannot use foreach() with $this->my

2004-03-02 Thread Philip Fletcher
> > You mean that the hasMore is being used just to > assure the current position is valid. While it should > be only used to confirm if there are more elements or > not. Right? > Absolutely. To avoid lots of confusion/bug reports, the current hasMore() should be renamed to isValid(). Philip

[PHP-DEV] Re: Iterator Class/foreach Logic Flaw? (was: [PHP-DEV] Cannot use foreach() with $this->my_iterator within a class)

2004-03-02 Thread Philip Fletcher
Hi Marc Please take a look at the thread headed 'Iterator Class/foreach Logic Flaw?' - you will find your hasMore() returns TRUE when place on the last element, but (in the exammple code below), there are only three elements - therefore when on the third element, hasMore() should return false...

[PHP-DEV] Cannot use foreach() with $this->my_iterator within a class

2004-03-02 Thread Philip Fletcher
The following code attempts to use a class's iterator member with foreach. This code will not run unless you comment out the offending foreach (marked '** Comment out the next three lines...'). As demonstrated, it is possible to get() the iterator class and run it using foreach() externally or to

[PHP-DEV] Iterator Class/foreach Logic Flaw?

2004-02-26 Thread Philip Fletcher
At the risk of making a complete fool of myself, I'd like to ask the smarter brains than me to checkout the current logic in the implementation of Iterator classes and foreach(). The current logic of foreach( $obj as $key => $val ) { ... } where $obj implements Iterator, is: for($obj->rewind(); $

Re: [PHP-DEV] Iterator Class/foreach Logic Flaw?

2004-02-26 Thread Philip Fletcher
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

Re: [PHP-DEV] Iterator Class/foreach Logic Flaw?

2004-02-26 Thread Philip Fletcher
Sorry for follow-up to myself, but it would be somewhat easier to just rename hasMore() to isValid() and then implement hasMore() after PHP5 goes gold. Philip Fletcher wrote: > Whilst I appreciate adding an isValid() method to the Iterator interface > is not trivial (and I am loath to sug

Re: [PHP-DEV] Iterator Class/foreach Logic Flaw?

2004-02-26 Thread Philip Fletcher
Hi Marcus Yes, the current implementation of hasMore() has an identical semantic to isValid(). The generally understood semantic of isValid() and hasMore() are quite different - hence the need for the rename. Regards Philip Marcus Boerger wrote: > Hello Philip, > > just to make it clear. has

Re: [PHP-DEV] Iterator Class/foreach Logic Flaw

2004-02-26 Thread 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