Where would you look for documentation about interface RecursiveIterator? RecursiveIteratorAggregate - suggestion

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

 




http://de.php.net/~helly/php/ext/spl/interfaceRecursiveIterator.html

This piece of code

------------------------
<?php
$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3);

$dir = new RecursiveIteratorIterator(new ArrayIterator($array));

foreach ($dir as $file) {
    print "$file\n";
}

?>
------------------------

results in

------------------------
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An instance of *RecursiveIterator* or IteratorAggregate creating it is required' in /tmp/t3.php:4
Stack trace:
/tmp/t3.php|4| RecursiveIteratorIterator->__construct(Object(ArrayIterator))
#1 {main}
  thrown in /tmp/t3.php on line 4
------------------------

So this interface exists.

Why am I asking?

I've written a small html combinator library where each tag is represented as object.
Now I want to iterate over them using RecursiveIteratorIterator.

To be able to iterate over subElements I have to provide subIterator
 by exposing the interface RecursiveIterator, right?

I'd like to also implement IteratorAggregate instead
of Iterator because subtags are stored in arrays.
This doesn't work because RecursiveIterator does inherit from Iterator.
Thus I have to implement current, next, etc as well just beeing dummy
functions calling an internal iterator iterating over those elements?

Or is this much easier and there is a RecursiveIteratorAggregate interface?

Marc

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