Home > Uncategorised > PHP Classes

PHP Classes

I’ve been investigating PHP classes (the version 4 kind) over the past couple of days, and I’ve now started to rewrite this website so that I use them in a more effective way.

In the past, the site was made up of a mish-mash of functions, and a variety of functions to output data in different formats (read: HTML and RSS). By turning it into classes, I can make it a much more intelligent process, and can separate (not entirely, but more than before) the application logic and display logic.

As an overview, I can tell you some of the basic details.

I have created 2 simple hierarchies of classes:

The first is the “databaseObject” hierarchy – this creates a generic base class for anything stored in the database, and then a class for each record type (i.e. database table). Further to this, I have created “holding” classes – essentially array manipulation classes.

The second hierarchy is the “formatter” hierarchy. I’ve created a base class with functions to output each class type. I then inherit this class for each output format that I want (e.g. HTML, xHTML, RSS, and others). Each one of these classes overrides the base methods (only those needed) from the base class, and formats the output according to how the format requires. This does mean though, that I need to generate the base output in the “master” PHP file (i.e. the file being executed and viewed) such as the base HTML page – but this is kind of desired anyway.

Hopefully, in the future I should be able to add facilities better, and also add output formats quite simply (without having to completely rewrite chunks of my site).

I’ll try and generate some form of UML diagram to make it a bit clearer, and post it here.

Categories: Uncategorised Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.