title: Problem with Global Variables
body: <p>I'm somewhat new to OOP programming so it's very likely I'm making some stupid mistake. Here is my problem. When running my code I get the following error:</p>
  
  <blockquote>
    <p><strong>Fatal error:</strong> Call to a member function checkLogin() on a non-object in <strong>/application/libraries/Session.php</strong> on line <strong>30</strong></p>
  </blockquote>
  
  <p>Below is the Session.php file (I've commented line 30 to make it easier to find):</p>
  
  <pre><code>&lt;?php
  require_once(LIBPATH . 'MySQLDB.php');
  require_once(LIBPATH . 'Authentication.php');
  
  class Session {
  public $url;
  public $referrer;
  public $redirect;
  
  function Session() {
      $this-&gt;startSession();
  }
  function startSession() {
      global $auth;
  
      session_start();
  
      if (isset($_SESSION['url'])) {
          $this-&gt;referrer = $_SESSION['url'];
      } else {
          $this-&gt;referrer = '/';
      }
      $this-&gt;url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
      if (isset($_SESSION['redirect'])) {
          $this-&gt;redirect = $_SESSION['redirect'];
      } else {
          $this-&gt;redirect = $_SESSION['redirect'] = '/';
      }
  
      $auth-&gt;checkLogin();         // LINE 30
  }
  function setRedirect($page) {
      $this-&gt;redirect = $_SESSION['redirect'] = $page;
  }
  }
  </code></pre>
  
  <p>In my attempts to troubleshoot the problem I put echo gettype($auth) between the includes and class declaration. The resulting output was "Object." I then tried putting echo gettype($auth) right after I declare global $auth in the startSession function. The resulting output was "NULL." Any idea as to what my problem may be? Thanks.</p>
  
  <p><strong>EDIT:</strong> $auth is declared in Authentication.php</p>