HomePHP Coding Examples of the Iterator, Countable and ArrayAccess SPL Interfaces in PHP 5
Coding Examples of the Iterator, Countable and ArrayAccess SPL Interfaces in PHP 5
Welcome to the final installment of a series that provides an overview of the Iterator, Countable and ArrayAccess SPL interfaces in PHP 5. Made up of six parts, this series teaches you how to build a fully-working MySQL abstraction class that takes advantage of the methods inherited from these native interfaces to manipulate database record sets easily by using an array syntax.
In the articles that preceded this one I demonstrated in a step-by-step fashion how to develop such a MySQL handling class. It effectively defined all of the methods required by the aforementioned interfaces. In doing so, the class now is not only capable of traversing data sets by way of a plain “foreach” construct, but it allows you to count and access rows in those sets as if they were array elements.
Of course, while describing the functionality of this sample class is fine, bragging about it is only the half of the story. It's necessary to show a few examples of how to use the class in a useful way. Therefore, in this last part of the series I’m going to code for you a few basic scripts that will show the actual functionality of this implementing class.
Does my proposal sound good to you? Then start reading now!