Welcome Guest, Not a member yet? Register   Sign In
Side Effect of loading it twice?
#1

[eluser]solid9[/eluser]
What is the side effect of loading a library or model or helper twice or more?

Example:

Controller A,
Code:
public function __construct()
{
$this->ci->load->library('sample_lib');
}

Controller B,
Code:
public function __construct()
{
$this->ci->load->library('sample_lib');
}

I hope Cronix or InsiteFX or someone that is much more experienced,
to answer this.

Just curious to know the side effect of loading it repeatedly.

Thanks in advanced.

#2

[eluser]PhilTem[/eluser]
You're effectively not loading it twice. You are in fact calling the load->library-method but that does not mean it gets loaded twice (if it was loaded twice it'd overwrite itself).
CI's business logic for loading files is: If you already loaded it we don't load it again:

Code:
if ($library === '' OR isset($this->_base_classes[$library]))
{
    return FALSE;
}

$this->_base_classes stores the name of every library loaded.
#3

[eluser]solid9[/eluser]
@PhilTem

Where did you get that codes?
Give me the right path for it.
I'll review it myself.

Thanks in advanced.
#4

[eluser]CroNiX[/eluser]
Check out /system/core/Loader.php, specifically the _ci_load_class() method. If something is already loaded, it just returns a reference to the loaded object. If not, it loads it.
#5

[eluser]solid9[/eluser]
I now understood.
Thanks guys.




Theme © iAndrew 2016 - Forum software by © MyBB