PHP 5 makes some significant improvements on the Object Orientated programming model of PHP 4, bringing it more in line with languages such as VB.NET and Java. The improved object model in PHP 5 makes developing applications using OOP much easier and gives you, the programmer greater flexibility.
I hope to use these tutorials to introduce to you some of the new features of the PHP 5 object model as well as create something which you will find useful in the process. I have therefore chosen as a test case, a database abstraction layer, similar to the Pear DB abstraction layer, however, not as feature rich, remember this is only a tutorial.
This thread is locked and I will add the next part of the tutorial on a regular basis, if you have any comments, criticisms, etc. about anything, please post them here.
Contents
Interfaces Abstract Classes and the Adapter Pattern
Protecting data with Visibility
Using Delegation and Type Hinting
Making use of the Factory Pattern to make Refactoring Easier
Introduction
One of PHP's stronger areas is it's support for database connectivity. It is able to connect to and talk to just about any database server / interface you can imagine. However, with this comes a few inherent problems; each database system has its own features, functions and in most cases they have their own versions of SQL although the functions used to access these databases are similar they do vary subtly meaning that if you were to want to port an application written for MySql to MS SQL server, the refactoring would require for example manually changing all calls to mysql_query() to mssql_query().
While we are not going to go as far as developing our database independent version of SQL, we shall use the new features of PHP 5 to help us build a consistent database API with support for stored procedures where it is not already present. This can then make switching from one database system to another as painless as changing one line of code.
Last edited by visualAd; Dec 29th, 2005 at 12:48 PM.