PHP: how to access methods from associated classes
<p>I have a class, who has a property that is a second class, who also has a property that is a third class:</p>

<pre><code>$classOne = new ClassOne;
$classOne-&gt;classTwo = new ClassTwo;
$classOne-&gt;classTwo-&gt;classThree = new ClassThree;
</code></pre>

<p>And, consequently, I can do this:</p>

<pre><code>$classOne-&gt;classTwo-&gt;classThree-&gt;someClassThreeMethod();
</code></pre>

<p>And what I'm trying to do is:</p>

<pre><code>classThree {
    someClassThreeMethod() {
        $classOne-&gt;someMethod();
        // some more code
    }
}
</code></pre>

<p>Whenever I try to do so, PHP tells me <code>Fatal error: Uncaught Error: Call to a member function someMethod() on null in...</code>
So, I tried setting <code>global $classOne</code> (inside <code>someClassThreeMethod</code>), and since it didn't work, also tried <code>$classOne</code> into <code>$GLOBALS</code> (didn't work either - on the global scope, outside ClassThree implementation).</p>

<p>So, finally, how do I access <code>someMethod</code> from within an associated class?</p>

<p><strong>UPDATE</strong><br>
I got a better idea on how to proceed with the answers given so far, so I'm reformulating to a slightly different question: how do I set <code>$classOne</code> to be accessible from within <code>someClassThreeMethod</code>?</p>