In any object oriented code, whenever you see a series of if/else or case statements, it's often better handled by an object hierarchy rather than a bunch if if/else/else.
In your particular case, you might instead have 3 different classes for A, B, and C. And just call a single $obj->doit() method. A, B, and C would each have different implementations of the doit() method.
If you want to get out of your rut, I recommend reading a book about design patterns. Here are some examples of design patterns in PHP: http://www.fluffycat.com/PHP-Design-Patterns/
Patterns that may be of particular interest to you for this particular type of problem are:
- Strategy.
- Command.
- Factory.
Descriptions of these patterns with PHP examples are in the above link. I do recommend reading up more about design patterns elsewhere, but that link has PHP examples.
I actually routinely use the 3 of those together to cleanly organize code in situations similar or identical to what you are describing. It works like this:
- Strategy. This is like a cookie-cutter or Mad Libs style of thing. You set up the basics involved in performing a function. The user (the programmer using the base class) can override certain things if he needs to, but the basics for doing the work are all in place. Example: we need to perform a business process. Generally that involves starting a transaction, doing the "meat" of the work, then performing cleanup and logging. Seems overkill perhaps to use a Stragegy/cookie-cutter pattern here, but it's often not: you need to remember to do the cleanup even if there was an error or exception thrown in the "meat" of the code. By using the Strategy/cookie-cutter pattern, you can make all that happen with minimal boilerplate/repeated code.
Command: Combined with the ideas of the Strategy pattern I mentioned above, you have less boilerplate code in your functions that do the actual work.
Factory. You use a factory method to generate the appropriate kind of command for the situation you're faced with.
Those 3 design patterns put together work very well for this kind of situation, and can lead to some very clean code where you never repeat yourself.
maschka below recommended using Smarty, which is a reasonable idea. A better idea, depending on your application, may be to use an MVC framework. If you're committed to the idea of sticking with PHP, then I recommend CakePHP and have had great success with it. It helps you to lay out your code in a very good way and help keep you out of trouble.