Iterating iterables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Iterating iterables

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code please.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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 );

                }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$obj->rewind()
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

oh....


thanks
Post Reply