Re: php5 iterate an object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Henrik Gemal wrote:
I have an object that looks like this:

Test Object

the class Test must implement 'Iterator'

e.g.

class Test implements Iterator
{

    /*
     * Iterator methods
     */
    public function rewind(){}
    public function current(){}
    public function valid(){}
    public function next(){}
    public function key(){}
    public function count(){}
}

you'll have to fill in the body of those methods
yourself!

once you have done that yuou will be able to do something like:

$t = new Test();
foreach($t as $key => $value) {
	echo $key,' - ',$value,"\n";
}

        (
            [config] => TestConfig Object
                (
                    [file:protected] => test.conf
                    [kill:protected] => 1
                )

            [location:private] => "test"
}


I'm trying to write an PHP5 iterator that can iterate over an object but I'm not sure how. The manual for PHP5 iterators seems to only work with arrays. How do I iterate over an object and only get the name of the attribute ("config") and not the entire name ("Test::config")

I'd question what you are trying to do; it sounds liek an Iterator is
not the right tool for the job.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux