Welcome Guest, Not a member yet? Register   Sign In
global $CI; vs $CI=&get;_instance();
#1

[eluser]sleddog[/eluser]
In reference to the following thread:

CI Memory Usage
http://ellislab.com/forums/viewthread/68826/

I have a general question:

When attempting to retrieve the super-global CI object... What is faster/better:

global $CI;

OR

$CI =& get_instance();
#2

[eluser]Pygon[/eluser]
The difference is nominal. Technically, global $CI would be faster (by an extremely small amount bordering on none), however exposing the global all over your script directly isn't very smart as this exposes it to things like UNSET or other overwriting of the entire variable, not just its contents.
#3

[eluser]barbazul[/eluser]
It's always better to avoid using global variables.
In the particular case of the Output class, the method is called very early in the core initialization so there is full control of the variable content.
A better practice would have been to call the load_class function as they do in _display_cache method (same class)
#4

[eluser]sleddog[/eluser]
Thanks guys... I'll use the $CI =& get_instance(); going forward...




Theme © iAndrew 2016 - Forum software by © MyBB