CodeIgniter Forums
why still checking loaded files even though include a file using 'include_once' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: why still checking loaded files even though include a file using 'include_once' (/showthread.php?tid=33023)



why still checking loaded files even though include a file using 'include_once' - El Forum - 08-12-2010

[eluser]noname11[/eluser]
Hey all! I have a problem about class Loader that why still checking loaded files even though include a file using 'include_once'. thanks very much

// Safety: Was the class already loaded by a previous call?
if (in_array($filepath, $this->_ci_loaded_files))
{
// Before we deem this to be a duplicate request, let's see
// if a custom object name is being supplied. If so, we'll
// return a new instance of the object
if ( ! is_null($object_name))
{
$CI =& get_instance();
if ( ! isset($CI->$object_name))
{
return $this->_ci_init_class($class, '', $params, $object_name);
}
}

$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}

include_once($filepath);
$this->_ci_loaded_files[] = $filepath;
return $this->_ci_init_class($class, '', $params, $object_name);


why still checking loaded files even though include a file using 'include_once' - El Forum - 08-13-2010

[eluser]mddd[/eluser]
Because the class is not only loaded but also instantiated. It would give problems if the class instance was overwritten every time you loaded it again.


why still checking loaded files even though include a file using 'include_once' - El Forum - 08-13-2010

[eluser]Georgi Budinov[/eluser]
Hmm btw this is actually interesting. I remember I ran through some tests on performance that turned out include/require _once have worse performance than require/include. The question is why it is include_once ?


why still checking loaded files even though include a file using 'include_once' - El Forum - 08-17-2010

[eluser]noname11[/eluser]
anyhow,thanks! guys.