title: understanding the load_class in CodeIgniter
body: <p>im trying to understand the framework structure in CodeIgniter and i have just started and came up with this little misunderstanding .</p>
  
  <p>so can somebody please help me under stand the following :-</p>
  
  <p>1- why do they use a reference to pass an instance of the class ... i mean why not just a simple variable ?</p>
  
  <p>2- and why does the function store the name of the class in an array instead of a "string variable" (please dont judge my php terms as im the worst at it ).. ?!</p>
  
  <pre><code>static $_classes = array();
                     ^^^^^^^ this cloud be just ("") or am i missing something
  </code></pre>
  
  <p>here is the function so you wont go looking for it .</p>
  
  <pre><code>function &amp;load_class($class, $directory = 'libraries', $prefix = 'CI_')
      {
          static $_classes = array();
  
          // Does the class exist?  If so, we're done...
          if (isset($_classes[$class]))
          {
              return $_classes[$class];
          }
  
          $name = FALSE;
  
          // Look for the class first in the local application/libraries folder
          // then in the native system/libraries folder
          foreach (array(APPPATH, BASEPATH) as $path)
          {
              if (file_exists($path.$directory.'/'.$class.'.php'))
              {
                  $name = $prefix.$class;
  
                  if (class_exists($name) === FALSE)
                  {
                      require($path.$directory.'/'.$class.'.php');
                  }
  
                  break;
              }
          }
  
          // Is the request a class extension?  If so we load it too
          if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
          {
              $name = config_item('subclass_prefix').$class;
  
              if (class_exists($name) === FALSE)
              {
                  require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
              }
          }
  
          // Did we find the class?
          if ($name === FALSE)
          {
              // Note: We use exit() rather then show_error() in order to avoid a
              // self-referencing loop with the Excptions class
              exit('Unable to locate the specified class: '.$class.'.php');
          }
  
          // Keep track of what we just loaded
          is_loaded($class);
  
          $_classes[$class] = new $name();
          return $_classes[$class];
      }
  </code></pre>