title: PHP access class inside another class
body: <p>So I have two classes like this:</p>
  
  <pre><code>class foo {
      /* code here */
  }
  $foo = new foo();
  class bar {
      global $foo;
      public function bar () {
          echo $foo-&gt;something();
      }
  }
  </code></pre>
  
  <p>I want to access the methods of foo inside all methods bar, without declaring it in each method inside bar, like this:</p>
  
  <pre><code>class bar {
      public function bar () {
          global $foo;
          echo $foo-&gt;something();
      }
      public function barMethod () {
          global $foo;
          echo $foo-&gt;somethingElse();
      }
      /* etc */
  }
  </code></pre>
  
  <p>I don't want to extend it, either. I tried using the var keyword, but it didn't seem to work. What do I do in order to access the other class "foo" inside all methods of bar?</p>