title: How to access an object in another class
body: <p>Here is my class Connection in <strong>class1.php</strong> page</p>
  
  <pre><code>class Connection{
     //my other functions
     public function insert_data()
       {
           //my code
       } 
  }
  </code></pre>
  
  <p>Here is my another class mydata in <strong>class2.php</strong> page</p>
  
  <pre><code>include('class1.php');
  $ob=new Connection(); //first class object
  class mydata
      {
         //my other functions
         $ob-&gt;insert_data();//my query passes through this insert_data()
      }
  </code></pre>
  
  <p>It returns an error : <strong>Fatal error: Call to a member function insert_data() on a non-object in //page link</strong> <br>
  What is the problem in my code?<br> Help me please </p>