Welcome Guest, Not a member yet? Register   Sign In
Question about get_instance and CI objects
#1

[eluser]Unknown[/eluser]
Greetings,

I'm trying to get a grasp on how CodeIgniter works internally in an effort to better understand php as well as CodeIgniter. I'm having troubles wrapping my mind around the scope and context from which certain calls are made.

Here's a example:

$CI =& get_instance();

My issue is, I never am able to determine the context from which this call is being made available to the calling source file. I am aware that get_instance is defined in CI_Controller and that it is created early on in the initialization of the CodeIgniter "super object". Unfortunately, I just don't understand how it's accessible with a call like that. My problem may be that I don't understand how it is that php makes functions available.

Please correct me if I am wrong, but isn't the CI object basically an array of objects instantiated in memory each time CodeIgniter is kicked off? If that's the case, why doesn't there have to be a reference in ones code to the object or the array index that holds the object that defines get_instance?

This brings to mind another maybe related thought I've been chewing on. In the CI_Controller class constructor this is happening:

foreach (is_loaded() as $var => $class)

{
$this->$var =& load_class($class);
}

Now, in the load_class function in Common.php an array of classes, "$_classes[$class]", is returned with the classes already instantiated by "new". So my question is, back to the foreach clause above; are we simply creating an array of named references in the $this variable? After the foreach loop is done, $var ceases to exist?

What becomes of the $_classes array after load_class is done?


Sorry about all the questions, I'm just really trying to understand how CodeIgniter works and I suppose how php does as well. It would indeed be simple enough to just follow the instructions in the user manual and use the framework, but I'd really like to have a better understanding of what's going on under the hood too. I hope someone has the time and inclination to help a struggling php noob get a more in depth view of how things work. I'd really appreciate it.

Thanks,
Mark





Theme © iAndrew 2016 - Forum software by © MyBB