Assign loaded class to variable within current scope
<p>I'm trying to setup some classes to work with, but I'm not really sure how to accomplish to following.</p>

<p>Let's say I have a class "foo" that I'm working in, and I want to use functions from another class called "loader". The purpose of this loader class is to load various other classes that I can then use within the "foo" class.</p>

<p>Example:</p>

<pre><code>class foo {
    function foo() {
        $this-&gt;load-&gt;model();
    }
}
</code></pre>

<p>For this to work I would first initiate the class "load":</p>

<pre><code>class foo {
    function foo() {
        $this-&gt;load = new loader;
        $this-&gt;load-&gt;model('some_model');
    }
}
</code></pre>

<p>Now I can use the functions from within the loader class. The next thing I want is for the loaded model to be accessible from within the class foo. Example:</p>

<pre><code>class foo {
    function foo() {
        $this-&gt;load = new loader;
        $this-&gt;load-&gt;model('some_model');
        $this-&gt;some_model-&gt;function_from_this_model();
    }
}
</code></pre>

<p>And this is where I get lost, because I'm not sure how to stay within the scope of the "foo" class. At any given time I'd like to be able to use <code>$this-&gt;load-&gt;model('some_model')</code> to load a new model, that becomes accessible through <code>$this-&gt;some_model</code>. Or <code>$this-&gt;load-&gt;something_else('some_name')</code> which becomes available through <code>$this-&gt;some_name</code>.</p>

<p>Here's a loader class example:</p>

<pre><code>class loader {
    function model($model_name) {
        require('models/'.$model_name.'.php');
        $model = new $model_name;
        // and what to do now, to get it back to the $this var from class foo?
    }
}
</code></pre>

<p>But all of this happens only within the scope of the loader class.</p>

<p>Any ideas on how to accomplish this?</p>

<p><strong>Edit</strong>:<br>
I know I can assign it directly to a variable, like <code>$this-&gt;model_name</code> = <code>$this-&gt;load-&gt;model('model_name')</code>, but that's what I'm trying to avoid. I'd like to be able to use this "load" subclass to be able to work within the scope of the class "foo".</p>
