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:
Fatal error: Call to a member function checkLogin() on a non-object in /application/libraries/Session.php on line 30
Below is the Session.php file (I've commented line 30 to make it easier to find):
<?php
require_once(LIBPATH . 'MySQLDB.php');
require_once(LIBPATH . 'Authentication.php');
class Session {
public $url;
public $referrer;
public $redirect;
function Session() {
$this->startSession();
}
function startSession() {
global $auth;
session_start();
if (isset($_SESSION['url'])) {
$this->referrer = $_SESSION['url'];
} else {
$this->referrer = '/';
}
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
if (isset($_SESSION['redirect'])) {
$this->redirect = $_SESSION['redirect'];
} else {
$this->redirect = $_SESSION['redirect'] = '/';
}
$auth->checkLogin(); // LINE 30
}
function setRedirect($page) {
$this->redirect = $_SESSION['redirect'] = $page;
}
}
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.
EDIT: $auth is declared in Authentication.php