Welcome Guest, Not a member yet? Register   Sign In
Loading resources within library
#1

[eluser]Code Arachn!d[/eluser]
Not sure if it's good or bad development standards - but I have several libraries that rely on other libraries (classes). Some make DB calls etc - so in my opinion it'd be good to be safe and load those libraries if not already loaded.

So I know the standard
Code:
$this->CI =& get_instance();

But my question is more along the lines that for the sake of performance that it'd make sense to just check if the resource is already loaded. Or is $this->CI->load->library() satisfactory to run this check - given the previous bugs in checking if class was already loaded.
#2

[eluser]Rick Jolly[/eluser]
I was curious too so I looked at the loader class. CI keeps a record of all loaded classes in an array and checks that a class isn't in the array before loading it. Here are the relevant lines from the loader:
Code:
// Safety:  Was the class already loaded by a previous call?
if (in_array($subclass, $this->_ci_classes))
{
    $is_duplicate = TRUE;
    log_message('debug', $class." class already loaded. Second attempt ignored.");
    return;
}
#3

[eluser]Code Arachn!d[/eluser]
I saw this (should've mentioned that) - but my curoristy is about performance - plus I saw posts in the forum about older versions having bugs with this ... it was more a question about proper coding standards and keeping the code safe...




Theme © iAndrew 2016 - Forum software by © MyBB