PHP
  Home arrow PHP arrow Iterators in the Simplest Sense: Trave...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Iterators in the Simplest Sense: Traversing Different Data Structures
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2006-03-15

    Table of Contents:
  • Iterators in the Simplest Sense: Traversing Different Data Structures
  • Extending the scope of iterators: building a file iterator class
  • Building a concrete example: using the “FileIterator” class
  • More iterators ahead: creating a MySQL result set iterator class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Iterators in the Simplest Sense: Traversing Different Data Structures


    (Page 1 of 4 )

    Here we are again. Welcome to the second tutorial of the series “Iterators in the simplest sense.” Just in case you didn’t know, this series introduces Iterators in PHP 4 – PHP 5, explaining their basic concepts, and teaches you how to use them in practical projects, which can be utilized as part of larger PHP applications.

    Introduction

    As you’ll probably recall, in the first tutorial of this series, I briefly explained the theory behind Iterators in PHP, and highlighted some of their benefits by constructing an array iterator class. As you know, this array iterator was created as a subclass of the abstract “Iterator” class that I defined at the beginning of the first article, demonstrating that building an iterating programming structure in PHP is not only easy, but also fun and instructive.

    Nevertheless, an array iterator class isn’t very useful when evaluated as a standalone structure, isolated from other programming modules that might exist within the same Web application. In accordance with this, the real power of such a structure is leveraged when used as a building block of larger programs, which can use at a lower level some (or all) the methods provided by the array iterator.

    In order to illustrate how you can implement an array iterator within your own PHP applications, without sacrificing much of its functionality, over this second installment of the series, I’ll show you how different data structures can be traversed by the same set of abstract methods (called an interface) defined previously within the base abstract “Iterator” class. Following this approach, I’ll provide a common interface for iterating over distinct types of data structures, no matter if they’re only flat text files, arrays or MySQL result sets.

    By the end of this tutorial, I hope you’ll have an accurate idea of how to use a generic Iterator structure. I will show how it is useful for traversing different data structures by providing specific implementations for each of the abstract methods defined within the base Iterator class. So, let’s not waste any more time and start building different iterators in PHP!

    More PHP Articles
    More By Alejandro Gervasio


       · In this second article, the Iterator pattern is applied to the development of...
       · Thanks. Learned a thing or two again. Nice to see how the base class can be extended...
       · Hi Matthijs,Thanks again for keeping yourself reading my PHP articles, and of...
       · Hi Matthijs,The code has been corrected. Again, thanks for spotting...
       · Thank you Charles for correcting the code of the article. I truly appreciate that....
       · "I'll provide you with a concise explanation of what an Iterator is, in conjunction...
       · Hello Matthijs,Thank you again for commenting on this article, as well as for...
       · Id love to see you write a indepth series on AJAX.
       · Dear Jonathan,I'd like to thank you for your compliments on this tutorial, and...
       · Thanks for taking the time to reply Alejandro. Appreciated.Keep up the great...
       · You're very welcome Matthijs. Thank you for your feedback and kind...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT