Calling objects of other class in php?
<p>I am working on a website with php/mysql. </p>

<p>I have 3 files <code>config.php</code>, <code>utils.php</code> and <code>member.php</code>. code of the files are as below,</p>

<p>config.php - <code>$objPath-&gt;docrootlibs</code> is fine, I am sure there is no problem with this.</p>

<pre><code>    /* Other library files &amp; their object */
    require($objPath-&gt;docrootlibs.'/utils.php');
    $objUtils = new utils();

    require($objPath-&gt;docrootlibs.'/member.php');
    $objMember = new member();
</code></pre>

<p>utils.php</p>

<pre><code>    class utils{
        function getCurrentDateTimeForMySQL(){
            return date("Y-m-d H:i:s");
        }
    }
</code></pre>

<p>members.php</p>

<pre><code>    class member{
        var $userid;
        var $username;

        function __construct(){
            $this-&gt;lastactivity = $objUtils-&gt;getCurrentDateTimeForMySQL();
        }
    }
</code></pre>

<p>Now when I am including the <code>config.php</code> inside a page <code>home.php</code> with simple php include statement and running that page then it gives me following error.</p>

<pre><code>Notice: Undefined variable: objUtils in D:\wamp\www\site\libs\member.php on line 17

Fatal error: Call to a member function getCurrentDateTimeForMySQL() on a non-object in D:\wamp\www\site\libs\member.php on line 17
</code></pre>

<p>Line numbers in error above are different, I just copied the specific part from the code here.</p>

<p>I am not understanding why its giving error, because objects of utils class is defined on config page before including the member class. It should detect that object. </p>

<p>Please check and help me to understand and correct this error.</p>

<p>Thanks!</p>
