Page 1 of 1

Iterating iterables

Posted: Sat Oct 14, 2006 1:15 pm
by Todd_Z
I have a class that has implements iterator, then a wrapper class for that class, I implement Iterator for both of these classes, however, when I try to iterate over the wrapper class, i get:

Code: Select all

Warning: rewind(): supplied argument is not a valid stream resource in /home/www/Class.php on line 50
Any ideas?

Posted: Sat Oct 14, 2006 1:24 pm
by John Cartwright
Code please.

Posted: Sat Oct 14, 2006 2:08 pm
by Todd_Z
FW_Object is the wrapper for DB_Object

Code that generates error:

Code: Select all

foreach ( $obj as $var => $val )
        echo "{$var}: {$val}\n";
DB_Object.php

Code: Select all

public function current ( ) { echo "\nDB_Object::current()";

                        $key = key( $this->obj );
                        if ( array_key_exists($key,$this->new) )
                                return $this->new->$key;
                        return current( $this->obj );

                }

                public function next ( ) { echo "\nDB_Object::next()";

                        next( $this->obj );
                        return $this->current();

                }

                public function key ( ) { echo "\nDB_Object::key()";

                        return key( $this->obj );

                }

                public function valid ( ) { echo "\nDB_Object::valid()";

                        $key = key( $this->obj );
                        return array_key_exists( $key, $this->obj );

                }

                public function rewind ( ) { echo "\nDB_Object::rewind()";

                        reset( $this->obj );

                }
FW_Object.php

Code: Select all

public function current ( ) { echo "\nFW_Object::current()";

                        return current( $this->dbo );

                }

                public function next ( ) { echo "\nFW_Object::next()";

                        return next( $this->dbo );

                }

                public function key ( ) { echo "\nFW_Object::key()";

                        return key( $this->dbo );

                }

                public function valid ( ) { echo "\nFW_Object::valid()";

                        return valid( $this->dbo );

                }

                public function rewind ( ) { echo "\nFW_Object::rewind()";

                        return rewind( $this->dbo );

                }

Posted: Sat Oct 14, 2006 2:13 pm
by feyd
$obj->rewind()

Posted: Sat Oct 14, 2006 3:34 pm
by Todd_Z
oh....


thanks