I’d like to see a simple code correction in the following method. You can see that the class has a default $config parameter initialized to FALSE, but the method itself assumes $config is an Array if it is !== NULL. That can introduce some bugs in libraries when $config is passed in as FALSE and not an array.
$config should default to NULL or an empty array.
/**
* Instantiates a class
*
* @access private
* @param string
* @param string
* @return null
*/
function _ci_init_class($class, $prefix = '', $config = FALSE)
{
// Is there an associated config file for this class?
if ($config === NULL)
{
$config = NULL;
if (file_exists(APPPATH.'config/'.$class.EXT))
{
include(APPPATH.'config/'.$class.EXT);
}
}
if ($prefix == '')
{
$name = (class_exists('CI_'.$class)) ? 'CI_'.$class : $class;
}
else
{
$name = $prefix.$class;
}
// Set the variable name we will assign the class to
$class = strtolower($class);
$classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
// Instantiate the class
$CI =& get_instance();
if ($config !== NULL)
{
$CI->$classvar = new $name($config);
}
else
{
$CI->$classvar = new $name;
}
}
