php - is it possible for an object to reference parent objects methods?
<p>Okay so I've got the hang of the basics writing classes and methods, and extending them.</p>

<p>I could easily write a massive class with all the methods I could possibly want or several classes that just keep extending each other in a chain. But things are starting to get difficult to manage.</p>

<p>I am wondering if I could do something like the following code so I can keep "modules" separated, and only fire them up when required.. I hope this makes some sort of sense as to what i'm hoping to achieve:</p>

<pre><code>// user/member handling methods "module"
class db_user
{
    public function some_method()
    {
        // code that requires parent(?) objects get_something() method
    }
}

// post handling methods "module"
class db_post
{
    public function some_method()
    {
        // code that requires parent(?) objects update_something() method
    }
}

class db_connect()
{
    public $db_user;
    public $db_post;

    public function __construct()
    {
        // database connection stuff
    }
    public function __destruct()
    {
        // blow up
    }

    // if i want to work with user/member stuff
    public function set_db_user()
    {
        $this-&gt;db_user = new db_user();
    }

    // if i want to work with posts
    public function set_db_post()
    {
        $this-&gt;db_post = new db_post();
    }

    // generic db access methods here, queries/updates etc.
    public function get_something()
    {
        // code to fetch something
    }

    public function update_something()
    {
        // code to fetch something
    }
}
</code></pre>

<p>So i would then create a new connection object:</p>

<pre><code>$connection = new db_connect();
</code></pre>

<p>Need to work with users so..</p>

<pre><code>$connection-&gt;set_db_user();
$connection-&gt;db_user-&gt;some_method();
</code></pre>

<p>And now i need to do something with posts so..</p>

<pre><code>$connection-&gt;set_db_post();
$connection-&gt;db_post-&gt;some_method();
$connection-&gt;db_post-&gt;some_other_method();
</code></pre>

<p>I hope someone can help me out here, I've been searching for a few days but can't seem to find any info other than to basically keep it all in one class or create an endless chain of extensions - which isn't helpful because while I want everything to work through one "interface" I still want to keep the "modules" separate.</p>

<p>My apologies if this seems utterly ridiculous somehow - I am a novice after all..</p>
