Archive for the 'spl' Category

iterators

Today I’ll look at some iterators: a set of classes in the SPL that implements various iterating patterns: ArrayIterator, AppendIterator, FilterIterator, LimitIterator and NoRewindIterator. Hopefully you’ll get a idea of what these are capable of and that you can get some new ideas for your day-to-day tasks.
Read more »

Countable

Today I will look at the Countable interface, it has a single function that needs to be implemented: count(), by implementing this you can ensure that there is a count() function ready to use on any given class that implements it. The Countable interface is used in other places in the SPL as well: the ArrayIterator and ArrayObject classes implements this interface ( and SqliteResult if present )
Read more »

SplObjectStorage

In this post I will look at SplObjectStorage: a container that allows to store objects uniquly without the need to compare them one by one.
Read more »

SplSubject

The SplObserver class, together with SplSubject, provides a interface for implementing the Observer pattern.
To quote wikipedia: The essence of this pattern is that one or more objects (called observers or listeners) are registered (or register themselves) to observe an event which may be raised by the observed object (the subject). (The object which may raise an event generally maintains a collection of the observers.)
Read more »

SplFileObject

PHP5.1 introduced a new file object, the SplFileObject, an object that can be used with any streams and implements RecursiveIterator & SeekableIterator for easy access to the stream iteself.

The documentation at php.net has the full API for the class, but to see how it behaves we will look at how this class can help us out with our day to day code.
Read more »