title: php object within object, getting the top level object instance
body: <p>I am experimenting with PHP OOP</p>
  
  <p>what i'm trying to find out is, Is it possible to access a object instance from withing a object that was created in this object instance?</p>
  
  <p>sounds confusing, so here is a example:</p>
  
  <p>contents of index</p>
  
  <pre><code>
      class mainclass {
          var $data;
          function __construct($data){
              $this->data = $data;
          }
          function echodata(){
              echo $this->data;
          }
          function start($classname){
              include $classname.'.php';
              $inner = new $classname();
              $inner->show();
          }
  
      }
  
      $mainclass = new mainclass('maininfostuff');
      $mainclass->start('innerclass');
  
  
  
      //i want it to echo "maininfostuff"
  </code></pre>
  
  <p>contents of innerclass.php</p>
  
  <pre><code>
  class innerclass{
          function show(){
              mainclass->echodata();//the problem is here
          }
  }
  </code></pre>
  
  <p>the purpose of this test case is to make the inner class decide if/when to run the mainclass echodata function</p>
  
  <p>how can the above example be accomplished? (without relying on static classes or singletons or extended classes)</p>
  
  <p><strong>edit:</strong>
  due to some confusion in answers i have edited the example</p>