Iterator and SPL Classes and Interfaces

This chapter demonstrates many classes, abstract classes, and interfaces, yet it only begins to touch on the full nature of SPL.

Table 6-3 is a quick-reference guide to the complete collection of SPL iterators, including some not mentioned in this chapter. For more information, see the SPL section of the PHP Manual at http://www.php.net/spl.

Table 6-3. Iterator and SPL classes and interfaces

Name

Type

Relationship

Description

ArrayObject

Class

Implements IteratorAggregate interface

Converts arrays and objects into iterators

ArrayIterator

Class

Implements Iterator interface

Used by ArrayObject; cannot be instantiated directly

CachingIterator

Class

Implements Iterator interface

Provides “look ahead by one” capability using hasNext( )

CachingRecursiveIterator

Class

Extends CachingIterator class; implements RecursiveIterator interface

Adds caching support to recursive iterators

DirectoryIterator

Class

Implements Iterator interface

An iterator for directory files

FilterIterator

Abstract class

Implements Iterator interface

Allows filtering of other iterators using accept( ) method

Iterator

Interface

Defines Iterator interface

Implements an iterator

IteratorAggregate

Interface

Defines IteratorAggregate interface

Allows classes to control iteration by returning iterator from getIterator( ) method

LimitIterator

Class

Implements Iterator interface

Emulates database LIMIT clause ...

Get Upgrading to PHP 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.