Possible Duplicate:
Loading multiple versions of the same class
What is the best way to setup different versions of PHP classes and toggle them based on a configuration value?
Here's my scenario (using Zend Framework - shouldn't matter, but might):
I have 2 different versions of a web service that I'd like to be able to call. I need to switch between them using a value in my config file.
Right now, I have a class that acts as a factory and determines what version of the class needs to be returned based on the config value. Both versions of the class that the factory returns extend the same abstract class, so once the factory returns the object, I can treat both versions the same in the rest of the code. This seems fine to me in theory, but I end up with code that looks like this in my factory class, which doesn't seem to be good practice:
require_once APPLICATION_PATH . '/models/Search/SearchModelV' . $this->config->model->version . '.php';
$model_class = 'Search_Model_V' . $this->config->model->version;
return new $model_class();
I'm using PHP 5.3, so I've implemented namespaces. Just throwing that out there in case it can be used as a solution.