title: Properly using classes in other classes in php?
body: <p>Should have asked someone this a long time ago.</p>
  
  <p>What is the best way to use other classes within another class?</p>
  
  <p>For instance, lets say I have an application class:</p>
  
  <pre><code>class Application
  {
      public function displayVar() {
          echo 'hello world';
      }
  }
  </code></pre>
  
  <p>and a database class</p>
  
  <pre><code>class Database
  {
      // connects to db on construct
      public function query() {
          // queries db
      }
  }
  </code></pre>
  
  <p>now, i want to add a function to my application class that uses a function from the db class</p>
  
  <pre><code>class Application
  {
      public function displayVar() {
          echo 'hello world';
      }
      public function getVar() {
          global $db;
          $sql = foo;
          $db-&gt;query($sql);
      }
  }
  </code></pre>
  
  <p>so then I have</p>
  
  <pre><code>$db = new Database();
  $app = new Application();
  $app-&gt;getVar('var');
  </code></pre>
  
  <p>Is there a better way of doing this? Really what I am looking for is the standard way of doing it, not another way of rigging it.</p>