PHP
  Home arrow PHP arrow The Iterator, Countable and ArrayAccess SPL Interfaces
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 
iPad news and developer info.
Ads by affinity 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Forums Sitemap 
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? 
Google.com  
PHP

The Iterator, Countable and ArrayAccess SPL Interfaces


By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2010-03-11


    Table of Contents:
  • The Iterator, Countable and ArrayAccess SPL Interfaces
  • Developing a basic MySQL abstraction class
  • Handling database result sets separately
  • Making the MySQLi_ResultWrapper class more functional

  • 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


    Summary: In this first part of a short series, I'm going to introduce you to using the Iterator, Countable and ArrayAccess interfaces that come with the Standard PHP Library. You'll see how to implement some of the methods declared by the Iterator interface within a class that manipulates MySQL result sets via an intuitive API.

    The Iterator, Countable and ArrayAccess SPL Interfaces
    (Page 1 of 4 )

    For many PHP developers eager to apply the object-oriented paradigm in a more thorough and consistent manner, the release of PHP 5 brought a number of handy features that allowed them to achieve this goal in a truly painless fashion. This isn’t breaking news, of course, but the inclusion of member visibility and abstract classes, the support for native exceptions and magic methods, to name just a few examples, gave the language the level of maturity that we see in it these days.

    In addition, among the features that were added to PHP 5, there exists the capacity for creating user-defined interfaces. This characteristic permits developers to do programming by contract without too many headaches. However, the support for interfaces doesn’t stop in “userland,” as the language also comes with the Standard PHP Library (SPL). The SPL includes a set of native classes and interfaces that make it easier to tackle common programming problems, such as overloading arrays, traversing directories recursively, and so forth.

    Included in the group of native interfaces bundled with the SPL, there are a few  that deserve a deeper analysis, as they’re frequently used by many developers nowadays. I’m talking specifically about the Iterator, Countable and ArrayAccess interfaces. When properly implemented, these interfaces allow you to traverse different data collections (e.g. database result sets) by using a simple “foreach” construct, as well as going backward and forward across those data, as when navigating regular arrays.

    Given the relevance that these native interfaces have for the average PHP developer, in this series of tutorials I’m going to demonstrate how to use them in the development of a pair of concrete classes, which as you’ll see in a few moments, will act like an abstraction layer for interacting with MySQL.

    Now, it’s time to start discovering the actual power behind the Iterator, Countable and ArrayAccess PHP 5 interfaces. Let’s jump in!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - MVC and the Zend Framework
    - PHP: Rendering Web Pages Using the Composite...
    - PHP: Creating Dynamic Web Pages with the Com...
    - Secure Encrypting and Decrypting for Your PH...
    - PHP: Creating Single View Objects with the C...
    - PHP: View Object Collections and the Composi...
    - Securing Your PHP Website
    - Determine Link Relevance and Unique Class C ...
    - PHP Composite View Design Pattern: Introduci...
    - Facebook PHP API Applications: A Second Look
    - Secure PHP Programming
    - Facebook PHP API Applications: Basic Introdu...
    - SOAP Servers and Web Services
    - Using XPath, SOAP, and More with Web Services
    - Web Services: SimpleXML


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek