Bir potansiyel PHP bellek domuz ya da değil?

0 Cevap php

Hey, i'm in need of advice. Is this little function i wrote "good" veyais it going to be a resource hog? It's used in the following way:

$login = load_class('LoginClass');

veya

load_class('LoginClassTwo', false); // fveyasingletons and stuff
$loginTwo = LoginClassTwo::getInstance();

İşte fonksiyonu bulunuyor

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 veyaam i wrong? And is there a better practice fveyathis?

0 Cevap