title: Accessing a class variable from another class
body: <p>I'm relatively new to the PHP OO concept. I've been messing around with the following,</p>
  
  <pre><code>&lt;?php
  
  require('class_database.php');
  require('class_session.php');
  
  class something {  
  
    $database = NULL;
    $session = NULL;
  
    function __construct() {
      $this-&gt;database = new database();
      $this-&gt;session = new session();
    }
  
    function login() {
      $this-&gt;session-&gt;doLogin();
    }
  }
  ?&gt;
  
  in another script
  
  $something = new something();
  $something-&gt;login();
  </code></pre>
  
  <p>In this example, <code>$database</code> has a constructor which creates a protected variable containing a MySQLi connection. It also has a function called <code>query()</code>.</p>
  
  <p>If <code>$session</code> needed to run <code>$database-&gt;query</code>, how can I go about it? Creating a new database class would be highly wasteful but I can't seem to access <code>$database</code> from <code>$session</code>.</p>
  
  <p>Have I created a big hassle for myself I should have avoided? I'm wanting session to provide login verification which would need to access the database to check credentials.</p>
  
  <p>Thanks for any help</p>