私はOOPプログラミングに少し慣れていないので、愚かな間違いを犯している可能性が非常に高いです。これが私の問題です。コードを実行すると、次のエラーが発生します。
致命的なエラー:30行目の/application/libraries/Session.phpにある非オブジェクトのメンバー関数checkLogin()を呼び出す
以下はSession.phpファイルです(見つけやすくするために30行目にコメントを付けました):
<?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;
}
}
問題のトラブルシューティングを試みる際に、includesとclass宣言の間にecho gettype($ auth)を配置しました。結果の出力は「オブジェクト」でした。次に、startSession関数でグローバル$ authを宣言した直後に、echo gettype($ auth)を配置してみました。結果の出力は「NULL」でした。私の問題が何であるかについて何か考えはありますか?ありがとう。
編集: $authはAuthentication.phpで宣言されています