Some of my custom library classes in /system/application/libraries are interdependent via require_once() statements. Loading one library class, therefore, also loaded classes it depends on. Code Igniter was unable to detect these dependent class loads. It only checks for classes loaded via $this->load->library()
For example, when I loaded a custom library class in my controller with:
$this->load->library(lib_class_name)
I got the following error message:
Fatal error: Cannot redeclare class lib_class_name
The CI loader only checks for classes loaded using $this->load->library(). The CI loader doesn’t detect classes loaded outside of $this->load->library()!! See below for the fix ...
In system/codeigniter/libraries/Loader.php, I changed line 749 from:
// Safety: Was the class already loaded by a previous call?
if (in_array($filepath, $this->_ci_classes))
{
$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
to:
// Safety: Was the class already loaded by a previous call?
if (in_array($filepath, $this->_ci_classes) or class_exists($filepath))
{
$is_duplicate = TRUE;
log_message('debug', $class." class already loaded. Second attempt ignored.");
return;
}
This fixed the problem.
This should probably added to the next CI version.
