[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...

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

2004-03-02 Thread Marc Dembogurski
Hi,     I used to implement the hasMore() method like this:     public function hasMore(){     if (key($this->container) === NULL ) return FALSE;     if ( (key($this->container)) <= (count($this->container)-1) )     {   return TRUE;     }else   return FALSE;   } And I think that is what

[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