PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Advanced OOP With SPL In PHP 5

Introduction

This article covers the extensions to PHP5’s OOP including SPL (Standard PHP Library) and how to use them in a real world setting.

For the purposes of this article it will be assumed that you already know about classes, interfaces, static members, and references. You should also understand some basic design patterns like Factory.

These concepts will be illustrated through the use of a conceptual database layer.

In web application programming, there is a propensity for programmers to write elaborate database abstraction layers for database portability. One such example is the PEAR::DB abstraction.

Unfortunately, as with any solution that requires writing once for all databases, the lowest common denominator database, say MySQL, is the maximum feature set your application can make use of.

An example of why this is undesirable is easily illustrated with the PostgreSQL CIDR data type. When operating with IP information, you may wish to do searches for partial matches, net masks or n-bit specializations. In fact you have 10 distinct IP data operators in PostgreSQL. MySQL, on the other hand, does not have these operators, or a native CIDR data type. All is not lost though, as you can convert the address to a long-ip and do bitwise operations on the data to achieve the same result. It is; however, less than desirable when the functionality already exists in the database natively.

The solution is to use the power of PHP5, Interfaces and SPL to get the most performance out of your database but still maintain code portability and the ability for your application to run on many different databases with minor modification.

In This Article