In PHP, I'm reading some data from a normalization table in a database, and depending on which columns are non-NULL, I need to create certain objects. Something along the lines of:
if (!empty($fridge_contents[0])) {
require('Cheese.php');
$someCheese = new Cheese;
}
Conditional instantiation is normal, but is it bad practice to conditionally read in your class code as you need it like this? Should I require
the class code in global scope rather than in a conditional block? Response time is pretty critical, so I'd prefer not to load every possible class of object in memory if I'm only going to be instantiating a small subset.