PHP
  Home arrow PHP arrow The Standard PHP Library, Part 2
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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

The Standard PHP Library, Part 2
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 17
    2004-12-14


    Table of Contents:
  • The Standard PHP Library, Part 2
  • The Array Object
  • Simple Array Iterators
  • Directory Iteration
  • Recursive Iteration

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    The Standard PHP Library, Part 2
    ( Page 1 of 5 )

    In our second article on the standard PHP library, David Fells explains the new Arrray object, introduces Iterators and the ArrayIterator, and discusses some practical examples of their usage. This article assumes a knowledge of how Exceptions work in PHP 5.

    Introduction

    In the first installment of my series on SPL, we talked about Exceptions. If you have not read it and are not yet familiar with how exceptions work in PHP 5, please do so here (http://www.devshed.com/showblog/6520/The-Standard-PHP-Library-Part-1). This article assumes knowledge of the Exception class. This installment will cover the new Array object, introduce Iterators and the ArrayIterator, and discuss some practical examples of their usage.

    An iterator is, as the name implies, an object that traverses the contents of another object. The object may be a simple array data type or it may be a complex class, but by using iterators, we can standardize the way we traverse objects. The more important concept, however, is providing a way to traverse an object without exposing its internal data structure. In addition to providing a standard interface for object traversal and keeping the internal structure of the object being traversed private, it is common to iterate an object using a filter or to have multiple pending traversals on a single object. Using an iterator allows us to do all this.

    The big picture objective behind using special objects such as Iterators is to achieve what is called loose coupling. Loose coupling is present when the internal behavior of objects can change without affecting the objects that interact with them. It also means that private class data is kept private and is not directly accessible to outside objects. This allows classes to store internal data in whatever way they like without forcing other objects to make assumptions about data storage when attempting to directly access class data. The new features in PHP 5 and the introduction of the SPL allow PHP developers to take advantage of these concepts in ways that were previously not possible. To get an overview of the new features in PHP 5 if you are not already familiar with them, have a look at my article: "What's New in PHP 5" (http://www.devshed.com/c/a/PHP/Whats-New-in-PHP-5/).

    We will discuss the new ArrayObject class as a precursor to our discussion on iterators, as the ArrayObject class serves as an excellent example for simple iteration routines.



     
     
    >>> More PHP Articles          >>> More By David Fells
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT