Hey, i m in need of advice. Is this little function i wrote "good" 或is it going to be a resource hog? It s used in the following way:
$login = load_class( LoginClass );
或
load_class( LoginClassTwo , false); // f或singletons and stuff
$loginTwo = LoginClassTwo::getInstance();
本职能
function load_class($class, $instantiate = TRUE){
static $obj = array(); // holds the instancec of the classes
$l = strtolower($class); // the name of the file is the name of the class but lowercased
if (isSet($obj[$l])) { // Do we have an instance?
return $obj[$l];
}
$file = classess/ . $l . .class.php ;
if (file_exists($file) && is_readable($file)) { // Can we read the file?
include $file;
if ($instantiate == FALSE) { // Do we need to instantiate?
$obj[$l] = TRUE;
} else {
$obj[$l] = new $class;
}
return $obj[$l];
}
return FALSE; }
I m concerned that this method is ineffective and it s going to consume too much memory 或am i wrong? And is there a better practice f或this?