Iterators

Table of Contents

SPL provides a set of iterators to traverse over objects.

SPL Iterators Class Tree

  • ArrayIterator
    • RecursiveArrayIterator
  • EmptyIterator
  • IteratorIterator
    • AppendIterator
    • CachingIterator
      • RecursiveCachingIterator
    • FilterIterator
      • CallbackFilterIterator
        • RecursiveCallbackFilterIterator
      • RecursiveFilterIterator
        • ParentIterator
      • RegexIterator
        • RecursiveRegexIterator
    • InfiniteIterator
    • LimitIterator
    • NoRewindIterator
  • MultipleIterator
  • RecursiveIteratorIterator
    • RecursiveTreeIterator
  • DirectoryIterator (extends SplFileInfo)
    • FilesystemIterator
      • GlobIterator
      • RecursiveDirectoryIterator

The AppendIterator class

Introduction

An Iterator that iterates over several iterators one after the other.

Class synopsis

AppendIterator
class AppendIterator extends IteratorIterator implements OuterIterator {
/* Methods */
public __construct ( void )
public void append ( Iterator $iterator )
public mixed current ( void )
public void getArrayIterator ( void )
public Iterator getInnerIterator ( void )
public int getIteratorIndex ( void )
public scalar key ( void )
public void next ( void )
public void rewind ( void )
public bool valid ( void )
/* Inherited methods */
public IteratorIterator::__construct ( Traversable $iterator )
public mixed IteratorIterator::current ( void )
public Traversable IteratorIterator::getInnerIterator ( void )
public scalar IteratorIterator::key ( void )
public void IteratorIterator::next ( void )
public void IteratorIterator::rewind ( void )
public bool IteratorIterator::valid ( void )
}

The ArrayIterator class

Introduction

This iterator allows to unset and modify values and keys while iterating over Arrays and Objects.

When you want to iterate over the same array multiple times you need to instantiate ArrayObject and let it create ArrayIterator instances that refer to it either by using foreach or by calling its getIterator() method manually.

Class synopsis

ArrayIterator
class ArrayIterator implements ArrayAccess , SeekableIterator , Countable , Serializable {
/* Methods */
public void append ( mixed $value )
public void asort ( void )
public __construct ([ mixed $array = array() [, int $flags = 0 ]] )
public int count ( void )
public mixed current ( void )
public array getArrayCopy ( void )
public void getFlags ( void )
public mixed key ( void )
public void ksort ( void )
public void natcasesort ( void )
public void natsort ( void )
public void next ( void )
public void offsetExists ( string $index )
public mixed offsetGet ( string $index )
public void offsetSet ( string $index , string $newval )
public void offsetUnset ( string $index )
public void rewind ( void )
public void seek ( int $position )
public string serialize ( void )
public void setFlags ( string $flags )
public void uasort ( string $cmp_function )
public void uksort ( string $cmp_function )
public string unserialize ( string $serialized )
public bool valid ( void )
}

The CachingIterator class

Introduction

This object supports cached iteration over another iterator.

Class synopsis

CachingIterator
class CachingIterator extends IteratorIterator implements OuterIterator , ArrayAccess , Countable {
/* Constants */
const integer CachingIterator::CALL_TOSTRING = 1 ;
const integer CachingIterator::CATCH_GET_CHILD = 16 ;
const integer CachingIterator::TOSTRING_USE_KEY = 2 ;
const integer CachingIterator::TOSTRING_USE_CURRENT = 4 ;
const integer CachingIterator::TOSTRING_USE_INNER = 8 ;
const integer CachingIterator::FULL_CACHE = 256 ;
/* Methods */
public __construct ( Iterator $iterator [, string $flags = self::CALL_TOSTRING ] )
public int count ( void )
public void current ( void )
public void getCache ( void )
public void getFlags ( void )
public Iterator getInnerIterator ( void )
public void hasNext ( void )
public scalar key ( void )
public void next ( void )
public void offsetExists ( string $index )
public void offsetGet ( string $index )
public void offsetSet ( string $index , string $newval )
public void offsetUnset ( string $index )
public void rewind ( void )
public void setFlags ( bitmask $flags )
public void __toString ( void )
public void valid ( void )
}

Predefined Constants

CachingIterator::CALL_TOSTRING

Convert every element to string.

CachingIterator::CATCH_GET_CHILD

Don't throw exception in accessing children.

CachingIterator::TOSTRING_USE_KEY

Use key for conversion to string.

CachingIterator::TOSTRING_USE_CURRENT

Use current for conversion to string.

CachingIterator::TOSTRING_USE_INNER

Use inner for conversion to string.

CachingIterator::FULL_CACHE

Cache all read data.

The CallbackFilterIterator class

Introduction

Class synopsis

CallbackFilterIterator
class CallbackFilterIterator extends FilterIterator implements OuterIterator {
/* Methods */
public __construct ( Iterator $iterator , callable $callback )
public string accept ( void )
/* Inherited methods */
public abstract bool FilterIterator::accept ( void )
public FilterIterator::__construct ( Iterator $iterator )
public mixed FilterIterator::current ( void )
public Iterator FilterIterator::getInnerIterator ( void )
public mixed FilterIterator::key ( void )
public void FilterIterator::next ( void )
public void FilterIterator::rewind ( void )
public bool FilterIterator::valid ( void )
}

Examples

The callback should accept up to three arguments: the current item, the current key and the iterator, respectively.

Example #1 Available callback arguments

<?php

/**
 * Callback for CallbackFilterIterator
 *
 * @param $current   Current item's value
 * @param $key       Current item's key
 * @param $iterator  Iterator being filtered
 * @return boolean   TRUE to accept the current item, FALSE otherwise
 */
function my_callback($current$key$iterator) {
    
// Your filtering code here
}

?>

Any callable may be used; such as a string containing a function name, an array for a method, or an anonymous function.

Example #2 Callback basic examples

<?php

$dir 
= new FilesystemIterator(__DIR__);

// Filter large files ( > 100MB)
function is_large_file($current) {
    return 
$current->isFile() && $current->getSize() > 104857600;
}
$large_files = new CallbackFilterIterator($dir'is_large_file');

// Filter directories
$files = new CallbackFilterIterator($dir, function ($current$key$iterator) {
    return 
$current->isDir() && ! $iterator->isDot();
});

?>

The DirectoryIterator class

Introduction

The DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.

Class synopsis

DirectoryIterator
class DirectoryIterator extends SplFileInfo implements SeekableIterator {
/* Methods */
public __construct ( string $path )
public DirectoryIterator current ( void )
public int getATime ( void )
public string getBasename ([ string $suffix ] )
public int getCTime ( void )
public string getExtension ( void )
public string getFilename ( void )
public int getGroup ( void )
public int getInode ( void )
public int getMTime ( void )
public int getOwner ( void )
public string getPath ( void )
public string getPathname ( void )
public int getPerms ( void )
public int getSize ( void )
public string getType ( void )
public bool isDir ( void )
public bool isDot ( void )
public bool isExecutable ( void )
public bool isFile ( void )
public bool isLink ( void )
public bool isReadable ( void )
public bool isWritable ( void )
public string key ( void )
public void next ( void )
public void rewind ( void )
public void seek ( int $position )
public string __toString ( void )
public bool valid ( void )
}

Changelog

Version Description
5.1.2 DirectoryIterator extends SplFileInfo.

The EmptyIterator class

Introduction

The EmptyIterator class for an empty iterator.

Class synopsis

EmptyIterator
class EmptyIterator implements Iterator {
/* Methods */
public void current ( void )
public void key ( void )
public void next ( void )
public void rewind ( void )
public void valid ( void )
}

The FilesystemIterator class

Introduction

The Filesystem iterator

Class synopsis

FilesystemIterator
class FilesystemIterator extends DirectoryIterator implements SeekableIterator {
/* Constants */
const integer FilesystemIterator::CURRENT_AS_PATHNAME = 32 ;
const integer FilesystemIterator::CURRENT_AS_FILEINFO = 0 ;
const integer FilesystemIterator::CURRENT_AS_SELF = 16 ;
const integer FilesystemIterator::CURRENT_MODE_MASK = 240 ;
const integer FilesystemIterator::KEY_AS_PATHNAME = 0 ;
const integer FilesystemIterator::KEY_AS_FILENAME = 256 ;
const integer FilesystemIterator::FOLLOW_SYMLINKS = 512 ;
const integer FilesystemIterator::KEY_MODE_MASK = 3840 ;
const integer FilesystemIterator::NEW_CURRENT_AND_KEY = 256 ;
const integer FilesystemIterator::SKIP_DOTS = 4096 ;
const integer FilesystemIterator::UNIX_PATHS = 8192 ;
/* Methods */
public __construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS ] )
public mixed current ( void )
public int getFlags ( void )
public string key ( void )
public void next ( void )
public void rewind ( void )
public void setFlags ([ int $flags ] )
/* Inherited methods */
public DirectoryIterator DirectoryIterator::current ( void )
public int DirectoryIterator::getATime ( void )
public string DirectoryIterator::getBasename ([ string $suffix ] )
public int DirectoryIterator::getCTime ( void )
public string DirectoryIterator::getExtension ( void )
public string DirectoryIterator::getFilename ( void )
public int DirectoryIterator::getGroup ( void )
public int DirectoryIterator::getInode ( void )
public int DirectoryIterator::getMTime ( void )
public int DirectoryIterator::getOwner ( void )
public string DirectoryIterator::getPath ( void )
public string DirectoryIterator::getPathname ( void )
public int DirectoryIterator::getPerms ( void )
public int DirectoryIterator::getSize ( void )
public string DirectoryIterator::getType ( void )
public bool DirectoryIterator::isDir ( void )
public bool DirectoryIterator::isDot ( void )
public bool DirectoryIterator::isExecutable ( void )
public bool DirectoryIterator::isFile ( void )
public bool DirectoryIterator::isLink ( void )
public bool DirectoryIterator::isReadable ( void )
public bool DirectoryIterator::isWritable ( void )
public string DirectoryIterator::key ( void )
public void DirectoryIterator::next ( void )
public void DirectoryIterator::rewind ( void )
public void DirectoryIterator::seek ( int $position )
public string DirectoryIterator::__toString ( void )
public bool DirectoryIterator::valid ( void )
}

Predefined Constants

FilesystemIterator::CURRENT_AS_PATHNAME

Makes FilesystemIterator::current return the pathname.

FilesystemIterator::CURRENT_AS_FILEINFO

Makes FilesystemIterator::current return an SplFileInfo instance.

FilesystemIterator::CURRENT_AS_SELF

Makes FilesystemIterator::current return $this (the FilesystemIterator).

FilesystemIterator::CURRENT_MODE_MASK

Masks FilesystemIterator::current

FilesystemIterator::KEY_AS_PATHNAME

Makes FilesystemIterator::key return the pathname.

FilesystemIterator::KEY_AS_FILENAME

Makes FilesystemIterator::key return the filename.

Makes RecursiveDirectoryIterator::hasChildren follow symlinks.

FilesystemIterator::KEY_MODE_MASK

Masks FilesystemIterator::key

FilesystemIterator::NEW_CURRENT_AND_KEY

Same as FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::CURRENT_AS_FILEINFO.

FilesystemIterator::SKIP_DOTS

Skips dot files (. and ..).

FilesystemIterator::UNIX_PATHS

Makes paths use Unix-style forward slash irrespective of system default.

Changelog

Version Description
5.3.1 Added FilesystemIterator::FOLLOW_SYMLINKS

The FilterIterator class

Introduction

This abstract iterator filters out unwanted values. This class should be extended to implement custom iterator filters. The FilterIterator::accept must be implemented in the subclass.

Class synopsis

FilterIterator
abstract class FilterIterator extends IteratorIterator implements OuterIterator {
/* Methods */
public abstract bool accept ( void )
public __construct ( Iterator $iterator )
public mixed current ( void )
public Iterator getInnerIterator ( void )
public mixed key ( void )
public void next ( void )
public void rewind ( void )
public bool valid ( void )
}

The GlobIterator class

Introduction

Iterates through a file system in a similar fashion to glob.

Class synopsis

GlobIterator
class GlobIterator extends FilesystemIterator implements SeekableIterator , Countable {
/* Methods */
public __construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO ] )
public int count ( void )
/* Inherited methods */
public FilesystemIterator::__construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS ] )
public mixed FilesystemIterator::current ( void )
public int FilesystemIterator::getFlags ( void )
public string FilesystemIterator::key ( void )
public void FilesystemIterator::next ( void )
public void FilesystemIterator::rewind ( void )
public void FilesystemIterator::setFlags ([ int $flags ] )
}

The InfiniteIterator class

Introduction

The InfiniteIterator allows one to infinitely iterate over an iterator without having to manually rewind the iterator upon reaching its end.

Class synopsis

InfiniteIterator
class InfiniteIterator extends IteratorIterator implements OuterIterator {
/* Methods */
public __construct ( Iterator $iterator )
public void next ( void )
/* Inherited methods */
public IteratorIterator::__construct ( Traversable $iterator )
public mixed IteratorIterator::current ( void )
public Traversable IteratorIterator::getInnerIterator ( void )
public scalar IteratorIterator::key ( void )
public void IteratorIterator::next ( void )
public void IteratorIterator::rewind ( void )
public bool IteratorIterator::valid ( void )
}

The IteratorIterator class

Introduction

This iterator wrapper allows the conversion of anything that is Traversable into an Iterator. It is important to understand that most classes that do not implement Iterators have reasons as most likely they do not allow the full Iterator feature set. If so, techniques should be provided to prevent misuse, otherwise expect exceptions or fatal errors.

Class synopsis

IteratorIterator
class IteratorIterator implements OuterIterator {
/* Methods */
public __construct ( Traversable $iterator )
public mixed current ( void )
public Traversable getInnerIterator ( void )
public scalar key ( void )
public void next ( void )
public void rewind ( void )
public bool valid ( void )
}

The LimitIterator class

Introduction

The LimitIterator class allows iteration over a limited subset of items in an Iterator.

Class synopsis

LimitIterator
class LimitIterator extends IteratorIterator implements OuterIterator {
/* Methods */
public __construct ( Iterator $iterator [, int $offset = 0 [, int $count = -1 ]] )
public mixed current ( void )
public Iterator getInnerIterator ( void )
public int getPosition ( void )
public mixed key ( void )
public void next ( void )
public void rewind ( void )
public int seek ( int $position )
public bool valid ( void )
}

Examples

Example #1 LimitIterator usage example

<?php

// Create an iterator to be limited
$fruits = new ArrayIterator(array(
    
'apple',
    
'banana',
    
'cherry',
    
'damson',
    
'elderberry'
));

// Loop over first three fruits only
foreach (new LimitIterator($fruits03) as $fruit) {
    
var_dump($fruit);
}

echo 
"\n";

// Loop from third fruit until the end
// Note: offset starts from zero for apple
foreach (new LimitIterator($fruits2) as $fruit) {
    
var_dump($fruit);
}

?>

The above example will output:

string(5) "apple"
string(6) "banana"
string(6) "cherry"

string(6) "cherry"
string(6) "damson"
string(10) "elderberry"

The MultipleIterator class

Introduction

An Iterator that sequentially iterates over all attached iterators

Class synopsis

MultipleIterator
class MultipleIterator implements Iterator {
/* Constants */
const integer MultipleIterator::MIT_NEED_ANY = 0 ;
const integer MultipleIterator::MIT_NEED_ALL = 1 ;
const integer MultipleIterator::MIT_KEYS_NUMERIC = 0 ;
const integer MultipleIterator::MIT_KEYS_ASSOC = 2 ;
/* Methods */
public __construct ([ int $flags = MultipleIterator::MIT_NEED_ALL|MultipleIterator::MIT_KEYS_NUMERIC ] )
public void attachIterator ( Iterator $iterator [, string $infos ] )
public void containsIterator ( Iterator $iterator )
public void countIterators ( void )
public array current ( void )
public void detachIterator ( Iterator $iterator )
public void getFlags ( void )
public array key ( void )
public void next ( void )
public void rewind ( void )
public void setFlags ( int $flags )
public void valid ( void )
}

Predefined Constants

MultipleIterator::MIT_NEED_ANY

Do not require all sub iterators to be valid in iteration.

MultipleIterator::MIT_NEED_ALL

Require all sub iterators to be valid in iteration.

MultipleIterator::MIT_KEYS_NUMERIC

Keys are created from the sub iterators position.

MultipleIterator::MIT_KEYS_ASSOC

Keys are created from sub iterators associated information.

The NoRewindIterator class

Introduction

This iterator cannot be rewound.

Class synopsis

NoRewindIterator
class NoRewindIterator extends IteratorIterator {
/* Methods */
public __construct ( Iterator $iterator )
public mixed current ( void )
public iterator getInnerIterator ( void )
public mixed key ( void )
public void next ( void )
public void rewind ( void )
public bool valid ( void )
/* Inherited methods */
public IteratorIterator::__construct ( Traversable $iterator )
public mixed IteratorIterator::current ( void )
public Traversable IteratorIterator::getInnerIterator ( void )
public scalar IteratorIterator::key ( void )
public void IteratorIterator::next ( void )
public void IteratorIterator::rewind ( void )
public bool IteratorIterator::valid ( void )
}

The ParentIterator class

Introduction

This extended FilterIterator allows a recursive iteration using RecursiveIteratorIterator that only shows those elements which have children.

Class synopsis

ParentIterator
class ParentIterator extends RecursiveFilterIterator implements RecursiveIterator , OuterIterator {
/* Methods */
public bool accept ( void )
public __construct ( RecursiveIterator $iterator )
public ParentIterator getChildren ( void )
public bool hasChildren ( void )
public void next ( void )
public void rewind ( void )
}

The RecursiveArrayIterator class

Introduction

This iterator allows to unset and modify values and keys while iterating over Arrays and Objects in the same way as the ArrayIterator. Additionally it is possible to iterate over the current iterator entry.

Class synopsis

RecursiveArrayIterator
class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator {
/* Methods */
public RecursiveArrayIterator getChildren ( void )
public bool hasChildren ( void )
/* Inherits */
public void ArrayIterator::append ( mixed $value )
public void ArrayIterator::asort ( void )
public ArrayIterator::__construct ([ mixed $array = array() [, int $flags = 0 ]] )
public int ArrayIterator::count ( void )
public mixed ArrayIterator::current ( void )
public array ArrayIterator::getArrayCopy ( void )
public void ArrayIterator::getFlags ( void )
public mixed ArrayIterator::key ( void )
public void ArrayIterator::ksort ( void )
public void ArrayIterator::natcasesort ( void )
public void ArrayIterator::natsort ( void )
public void ArrayIterator::next ( void )
public void ArrayIterator::offsetExists ( string $index )
public mixed ArrayIterator::offsetGet ( string $index )
public void ArrayIterator::offsetSet ( string $index , string $newval )
public void ArrayIterator::offsetUnset ( string $index )
public void ArrayIterator::rewind ( void )
public void ArrayIterator::seek ( int $position )
public string ArrayIterator::serialize ( void )
public void ArrayIterator::setFlags ( string $flags )
public void ArrayIterator::uasort ( string $cmp_function )
public void ArrayIterator::uksort ( string $cmp_function )
public string ArrayIterator::unserialize ( string $serialized )
public bool ArrayIterator::valid ( void )
}

The RecursiveCachingIterator class

Introduction

...

Class synopsis

RecursiveCachingIterator
class RecursiveCachingIterator extends CachingIterator implements Countable , ArrayAccess , OuterIterator , RecursiveIterator {
/* Methods */
public __construct ( Iterator $iterator [, string $flags = self::CALL_TOSTRING ] )
public RecursiveCachingIterator getChildren ( void )
public bool hasChildren ( void )
/* Inherits */
public CachingIterator::__construct ( Iterator $iterator [, string $flags = self::CALL_TOSTRING ] )
public int CachingIterator::count ( void )
public void CachingIterator::current ( void )
public void CachingIterator::getCache ( void )
public void CachingIterator::getFlags ( void )
public Iterator CachingIterator::getInnerIterator ( void )
public void CachingIterator::hasNext ( void )
public scalar CachingIterator::key ( void )
public void CachingIterator::next ( void )
public void CachingIterator::offsetExists ( string $index )
public void CachingIterator::offsetGet ( string $index )
public void CachingIterator::offsetSet ( string $index , string $newval )
public void CachingIterator::offsetUnset ( string $index )
public void CachingIterator::rewind ( void )
public void CachingIterator::setFlags ( bitmask $flags )
public void CachingIterator::__toString ( void )
public void CachingIterator::valid ( void )
}

The RecursiveCallbackFilterIterator class

Introduction

Class synopsis

RecursiveCallbackFilterIterator
class RecursiveCallbackFilterIterator extends CallbackFilterIterator implements OuterIterator , RecursiveIterator {
/* Methods */
public __construct ( RecursiveIterator $iterator , string $callback )
public RecursiveCallbackFilterIterator getChildren ( void )
public void hasChildren ( void )
/* Inherited methods */
public string CallbackFilterIterator::accept ( void )
}

Examples

The callback should accept up to three arguments: the current item, the current key and the iterator, respectively.

Example #1 Available callback arguments

<?php

/**
 * Callback for RecursiveCallbackFilterIterator
 *
 * @param $current   Current item's value
 * @param $key       Current item's key
 * @param $iterator  Iterator being filtered
 * @return boolean   TRUE to accept the current item, FALSE otherwise
 */
function my_callback($current$key$iterator) {
    
// Your filtering code here
}

?>

Filtering a recursive iterator generally involves two conditions. The first is that, to allow recursion, the callback function should return TRUE if the current iterator item has children. The second is the normal filter condition, such as a file size or extension check as in the example below.

Example #2 Recursive callback basic example

<?php

$dir 
= new RecursiveDirectoryIterator(__DIR__);

// Filter large files ( > 100MB)
$files = new RecursiveCallbackFilterIterator($dir, function ($current$key$iterator) {
    
// Allow recursion
    
if ($iterator->hasChildren()) {
        return 
TRUE;
    }
    
// Check for large file
    
if ($current->isFile() && $current->getSize() > 104857600) {
        return 
TRUE;
    }
    return 
FALSE;
});
 
foreach (new 
RecursiveIteratorIterator($files) as $file) {
    echo 
$file->getPathname() . PHP_EOL;
}

?>

The RecursiveDirectoryIterator class

Introduction

The RecursiveDirectoryIterator provides an interface for iterating recursively over filesystem directories.

Class synopsis

RecursiveDirectoryIterator
class RecursiveDirectoryIterator extends FilesystemIterator implements SeekableIterator , RecursiveIterator {
/* Methods */
public __construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO ] )
public mixed getChildren ( void )
public string getSubPath ( void )
public string getSubPathname ( void )
public bool hasChildren ([ bool $allow_links = false ] )
public string key ( void )
public void next ( void )
public void rewind ( void )
/* Inherits */
public FilesystemIterator::__construct ( string $path [, int $flags = FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS ] )
public mixed FilesystemIterator::current ( void )
public int FilesystemIterator::getFlags ( void )
public string FilesystemIterator::key ( void )
public void FilesystemIterator::next ( void )
public void FilesystemIterator::rewind ( void )
public void FilesystemIterator::setFlags ([ int $flags ] )
}

Changelog

Version Description
5.3.0 The FilesystemIterator was introduced as the parent class. Previously, the parent was the DirectoryIterator.
5.3.0 Implements SeekableIterator.
5.2.11, 5.3.1 Added RecursiveDirectoryIterator::FOLLOW_SYMLINKS

The RecursiveFilterIterator class

Introduction

This abstract iterator filters out unwanted values for a RecursiveIterator. This class should be extended to implement custom filters. The RecursiveFilterIterator::accept must be implemented in the subclass.

Class synopsis

RecursiveFilterIterator
abstract class RecursiveFilterIterator extends FilterIterator implements OuterIterator , RecursiveIterator {
/* Methods */
public __construct ( RecursiveIterator $iterator )
public void getChildren ( void )
public void hasChildren ( void )
/* Inherited methods */
public abstract bool FilterIterator::accept ( void )
public FilterIterator::__construct ( Iterator $iterator )
public mixed FilterIterator::current ( void )
public Iterator FilterIterator::getInnerIterator ( void )
public mixed FilterIterator::key ( void )
public void FilterIterator::next ( void )
public void FilterIterator::rewind ( void )
public bool FilterIterator::valid ( void )
}

The RecursiveIteratorIterator class

Introduction

Can be used to iterate through recursive iterators.

Class synopsis

RecursiveIteratorIterator
class RecursiveIteratorIterator implements OuterIterator {
/* Constants */
const integer RecursiveIteratorIterator::LEAVES_ONLY = 0 ;
const integer RecursiveIteratorIterator::SELF_FIRST = 1 ;
const integer RecursiveIteratorIterator::CHILD_FIRST = 2 ;
const integer RecursiveIteratorIterator::CATCH_GET_CHILD = 16 ;
/* Methods */
public void beginChildren ( void )
public void beginIteration ( void )
public RecursiveIterator callGetChildren ( void )
public bool callHasChildren ( void )
public __construct ( Traversable $iterator [, int $mode = RecursiveIteratorIterator::LEAVES_ONLY [, int $flags = 0 ]] )
public mixed current ( void )
public void endChildren ( void )
public void endIteration ( void )
public int getDepth ( void )
public iterator getInnerIterator ( void )
public mixed getMaxDepth ( void )
public RecursiveIterator getSubIterator ([ int $level ] )
public mixed key ( void )
public void next ( void )
public void nextElement ( void )
public void rewind ( void )
public void setMaxDepth ([ string $max_depth = -1 ] )
public bool valid ( void )
/* Inherited methods */
public Iterator OuterIterator::getInnerIterator ( void )
}

Predefined Constants

RecursiveIteratorIterator::LEAVES_ONLY

RecursiveIteratorIterator::SELF_FIRST

RecursiveIteratorIterator::CHILD_FIRST

RecursiveIteratorIterator::CATCH_GET_CHILD

The RecursiveRegexIterator class

Introduction

This recursive iterator can filter another recursive iterator via a regular expression.

Class synopsis

RecursiveRegexIterator
class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator {
/* Methods */
public __construct ( RecursiveIterator $iterator , string $regex [, int $mode = self::MATCH [, int $flags = 0 [, int $preg_flags = 0 ]]] )
public RecursiveRegexIterator getChildren ( void )
public bool hasChildren ( void )
/* Inherited methods */
public RecursiveIterator RecursiveIterator::getChildren ( void )
public bool RecursiveIterator::hasChildren ( void )
public bool RegexIterator::accept ( void )
public int RegexIterator::getFlags ( void )
public int RegexIterator::getMode ( void )
public int RegexIterator::getPregFlags ( void )
public string RegexIterator::getRegex ( void )
public void RegexIterator::setFlags ( int $flags )
public void RegexIterator::setMode ( int $mode )
public void RegexIterator::setPregFlags ( int $preg_flags )
}

The RecursiveTreeIterator class

Introduction

Allows iterating over a RecursiveIterator to generate an ASCII graphic tree.

Class synopsis

RecursiveTreeIterator
class RecursiveTreeIterator extends RecursiveIteratorIterator implements OuterIterator {
/* Constants */
const integer RecursiveTreeIterator::BYPASS_CURRENT = 4 ;
const integer RecursiveTreeIterator::BYPASS_KEY = 8 ;
const integer RecursiveTreeIterator::PREFIX_LEFT = 0 ;
const integer RecursiveTreeIterator::PREFIX_MID_HAS_NEXT = 1 ;
const integer RecursiveTreeIterator::PREFIX_MID_LAST = 2 ;
const integer RecursiveTreeIterator::PREFIX_END_HAS_NEXT = 3 ;
const integer RecursiveTreeIterator::PREFIX_END_LAST = 4 ;
const integer RecursiveTreeIterator::PREFIX_RIGHT = 5 ;
/* Methods */
public void beginChildren ( void )
public RecursiveIterator beginIteration ( void )
public RecursiveIterator callGetChildren ( void )
public bool callHasChildren ( void )
public __construct ( RecursiveIterator|IteratorAggregate $it [, int $flags = RecursiveTreeIterator::BYPASS_KEY [, int $cit_flags = CachingIterator::CATCH_GET_CHILD [, int $mode = RecursiveIteratorIterator::SELF_FIRST ]]] )
public string current ( void )
public void endChildren ( void )
public void endIteration ( void )
public string getEntry ( void )
public void getPostfix ( void )
public string getPrefix ( void )
public string key ( void )
public void next ( void )
public void nextElement ( void )
public void rewind ( void )
public void setPrefixPart ( int $part , string $value )
public bool valid ( void )
/* Inherited methods */
public void RecursiveIteratorIterator::beginChildren ( void )
public void RecursiveIteratorIterator::beginIteration ( void )
public RecursiveIterator RecursiveIteratorIterator::callGetChildren ( void )
public bool RecursiveIteratorIterator::callHasChildren ( void )
public RecursiveIteratorIterator::__construct ( Traversable $iterator [, int $mode = RecursiveIteratorIterator::LEAVES_ONLY [, int $flags = 0 ]] )
public mixed RecursiveIteratorIterator::current ( void )
public void RecursiveIteratorIterator::endChildren ( void )
public void RecursiveIteratorIterator::endIteration ( void )
public int RecursiveIteratorIterator::getDepth ( void )
public iterator RecursiveIteratorIterator::getInnerIterator ( void )
public mixed RecursiveIteratorIterator::getMaxDepth ( void )
public RecursiveIterator RecursiveIteratorIterator::getSubIterator ([ int $level ] )
public mixed RecursiveIteratorIterator::key ( void )
public void RecursiveIteratorIterator::next ( void )
public void RecursiveIteratorIterator::nextElement ( void )
public void RecursiveIteratorIterator::rewind ( void )
public void RecursiveIteratorIterator::setMaxDepth ([ string $max_depth = -1 ] )
public bool RecursiveIteratorIterator::valid ( void )
}

Predefined Constants

RecursiveTreeIterator::BYPASS_CURRENT

RecursiveTreeIterator::BYPASS_KEY

RecursiveTreeIterator::PREFIX_LEFT

RecursiveTreeIterator::PREFIX_MID_HAS_NEXT

RecursiveTreeIterator::PREFIX_MID_LAST

RecursiveTreeIterator::PREFIX_END_HAS_NEXT

RecursiveTreeIterator::PREFIX_END_LAST

RecursiveTreeIterator::PREFIX_RIGHT

The RegexIterator class

Introduction

This iterator can be used to filter another iterator based on a regular expression.

Class synopsis

RegexIterator
class RegexIterator extends FilterIterator {
/* Constants */
const integer MATCH = 0 ;
const integer GET_MATCH = 1 ;
const integer ALL_MATCHES = 2 ;
const integer SPLIT = 3 ;
const integer REPLACE = 4 ;
const integer USE_KEY = 1 ;
/* Methods */
public __construct ( Iterator $iterator , string $regex [, int $mode = self::MATCH [, int $flags = 0 [, int $preg_flags = 0 ]]] )
public bool accept ( void )
public int getFlags ( void )
public int getMode ( void )
public int getPregFlags ( void )
public string getRegex ( void )
public void setFlags ( int $flags )
public void setMode ( int $mode )
public void setPregFlags ( int $preg_flags )
/* Inherited methods */
public abstract bool FilterIterator::accept ( void )
public FilterIterator::__construct ( Iterator $iterator )
public mixed FilterIterator::current ( void )
public Iterator FilterIterator::getInnerIterator ( void )
public mixed FilterIterator::key ( void )
public void FilterIterator::next ( void )
public void FilterIterator::rewind ( void )
public bool FilterIterator::valid ( void )
}

Predefined Constants

RegexIterator operation modes

RegexIterator::ALL_MATCHES

Return all matches for the current entry (see preg_match_all).

RegexIterator::GET_MATCH

Return the first match for the current entry (see preg_match).

RegexIterator::MATCH

Only execute match (filter) for the current entry (see preg_match).

RegexIterator::REPLACE

Replace the current entry (see preg_replace; Not fully implemented yet)

RegexIterator::SPLIT

Returns the split values for the current entry (see preg_split).

RegexIterator Flags

RegexIterator::USE_KEY

Special flag: Match the entry key instead of the entry value.