The Netlobo logo - a Nevada desert landscape

PHP Application Feature Management

A method for managing multiple features in a large PHP application.

Published Dec 2, 2005 by lobo235
Last updated on May 19, 2009

Recently I have been working on a large PHP application that is used by multiple clients. Some of the clients request new features to be added to the application that other clients may not want or need. In the past I have just made a copy of the PHP code and put it into a separate folder and then I add the features they request. This helps to separate the features so that other clients do not see them but it does not make it easy to manage all of the features. I have run into the problem that sometimes two clients will want the same feature added but at the same time they have other features that differ from each other. In order to make things easier I have come up with a new method to manage all of the features so they can be used by any of the clients just by "turning them on." In this article I will share the method I now use to manage new features made to my PHP applications.

The first thing that I needed to determine was a method to keep track of the features added to the application. In my application, each client has their own separate MySQL database with tables that store all the information specific to that client. I have created a new table in each client's database that has a field for each of the features that are available. When a client uses a particular feature I put a number 1 in that field, if they do not use the feature I leave it at 0.

The next thing that I needed to figure out was how I was going to write the actual PHP code so that the features could be turned on or off easily. The method that I came up with was to write the features in separate files that could be included in the PHP code at the location where the functionality needs to be changed. Typically this is done with an "if" statement. So, for example, if the client wants a new feature that emails them every time a specific event occurs I write the code to send the email in a separate file called something like email_notification.php and include it right after that event occurs in the PHP code. Some features are meant to change already existing functionality so in these cases I use an "if-else" statement to include the PHP feature file instead of using the PHP code that is already in place.

Sometimes it gets a bit more complicated. Some features require that changes be made to multiple PHP files. In these cases I create multiple PHP feature files so I can include each one where it is needed. Going back to the email notification example above, if the client wanted multiple notifications to be added throughout the application I create files like email_notification1.php, email_notification2.php, and so on. Each one of these PHP files is then included where it is needed using the same "if" or "if-else" statement.

Here is an example of what this actually looks like in the PHP application. Before this to work, I have to read the row from the features table for that client and populate the $features array with the values from that row.

<?php
    
if( $features['email_notification'] == )
    {
        include 
'features/email_notification.php';
    }
    else
    {
        
// Default functionality goes here
    
}
?>

Using this method has made my PHP application a lot more manageable and makes it very easy to turn features on and off for each client. Now the features are reusable and easy to manage.

0 comments for this article. Be the first to leave one!

Other great Web Development and Programming articles on Netlobo.com:
Checkbox Magic - Checking, Unchecking, and Inverting with Javascript
Clear File Input Using Javascript
Showing/Hiding a DIV using the Off-Left Method