title: PHP OOP - getting instance of object into another class
body: <p>I want to get an instance of an existing object. How do I do this without having to pass the object as a parameter? This is what I'm doing now:</p>
  
  <pre><code>class clas1 {
      public $myArray;
  
      public function setArray($a){
          $this-&gt;myArray = $a;
      }
  }
  
  class clas2 {
      public $test;
  
      function __construct($obj) {
          $this-&gt;test = $obj;
      }
  }
  
  $c = new clas1;
  $c-&gt;setArray(array('firstname'=&gt;'Fred'));
  
  $c2 = new clas2($c);
  
  var_dump($c2);
  </code></pre>
  
  <p>The output of var_dump is:</p>
  
  <pre><code>object(clas2)[2]
    public 'test' =&gt; 
      object(clas1)[1]
        public 'myArray' =&gt; 
          array
            'firstname' =&gt; string 'Fred' (length=4)
  </code></pre>
  
  <p>I suppose I could have each object as a property of a parent object, but is are there any other suggestions?</p>