[ Team LiB ] Previous Section Next Section



You mentioned books about object-oriented design. Can you be more specific?


Because PHP 5 is so new, there are few books focusing on object-oriented design with PHP at the time of writing. This will probably not be the case as you read this sentence, so you might consider a visit to your local bookstore. If you have any knowledge of C++, we recommend a book called Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma et al. If you have a background in Java, we recommend Design Patterns Explained by Alan Shalloway and James R. Trott. The magazine PHP|architect focuses on objects in many of its articles (http://www.phparchitect.com). Another good source for object-oriented information is phpPatterns at http://www.phppatterns.com.


Is there any way of simulating abstract classes or interfaces in PHP 4?


It would be hard to emulate an interface with PHP 4. Abstract classes, however, can be simulated. Define a base class, and ensure that every "abstract" method contains a die() statement:

function doThing() {
   die( "doThing() is abstract and must be overridden" );

This is clearly not as satisfactory as PHP 5's abstract classes, but it can be deployed quite effectively nevertheless.

    [ Team LiB ] Previous Section Next Section