致命错误:未捕获错误:调用成员函数

时间:2018-03-31 10:45:36

标签: php apache

尝试从Apache提供PHP代码时出现此错误:

  

注意:未定义的变量:社区   第1行的/var/www/Account/assets/includes/head/nav.php

     

致命错误:未捕获错误:调用成员函数getUser()on   /var/www/Account/assets/includes/head/nav.php:1中的null堆栈跟踪:   #0 /var/www/Account/assets/includes/head.php(60):include_once()#1 /var/www/Account/cpanel/community.php(3):   包括(' / var / www / Accoun ...')#2   /var/www/Account/assets/classes/core.php(14):   require_once(' / var / www / Accoun ...')#3   /var/www/Account/assets/includes/head.php(7):   require_once(' / var / www / Accoun ...')#4   /var/www/Account/cpanel/home.php(3):include(' / var / www / Accoun ...')#5   {main}投放在/var/www/Account/assets/includes/head/nav.php上线   1

在Windows中的XAMPP工作中,我没有收到错误;但在使用Apache的Linux上并没有。两者都使用PHP 7.1

head.php 中的内容:

<!DOCTYPE html>
<?php
include_once("config/min.php");

session_start();
define('ROOTPATH', __DIR__);
require_once(ROOTPATH.'/../classes/core.php');

if ($USER->is_logged_in())  {
  $stmt = $USER->runQuery("SELECT * FROM users WHERE id=:uid");
  $stmt->execute(array(":uid"=>$_SESSION['userSession']));
  $U_DATA = $stmt->fetch(PDO::FETCH_ASSOC);
}

?>
<html>
  <head>

    <title><?php echo $title; ?></title>

    <?php include_once("head/styles.php"); ?>

    <?php include_once("config/ads.php"); ?>
  </head>

    <body>
    <?php include_once("head/nav.php"); ?>

core.php

中的内容
<?php

require_once 'init.php';
require_once 'PasswordStorage.php';


require_once 'user.php';
$USER = new USER();

require_once 'community.php';
$COMMUNITY = new COMMUNITY();

?>

nav.php

中的内容
<?php if (!strpos($_SERVER['REQUEST_URI'], "a/")) { if ($USER->is_logged_in()) { $C_USER = $COMMUNITY->getUser($U_DATA['id']); } ?>
<div class="wrapper">
...

community.php

中的内容
<?php

class COMMUNITY
{
    private $conn;
    public function __construct() {
        $database = new Database();
        $db = $database->dbConnection();
        $this->conn = $db;
    }

    private function request($path) {
        $url = "https://community.makeroid.io";
        $api_key = "XXX";
        $api_user = "system";
        $request = file_get_contents($url."/".$path."?api_key=".$api_key."&api_username=".$api_user);
        if ($request) {
            return json_decode($request, true);
        } else {
            return false;
        }

    }

    public function getUser($id) {
        $stmt = $this->conn->prepare("SELECT * FROM c_users WHERE u_id=:id;");
        $stmt->bindparam(":id",$id);
        $stmt->execute();
        $user = $stmt->fetchAll(PDO::FETCH_ASSOC);
        if (count($user) == 1) {
            return $user[0];
        } else {
            return null;
        }
    }

    public function verifyUser($username, $id, $email) {
        $emails = $this->request("users/".$username."/emails.json");
        if ($emails) {
            if ($emails['email'] == $email) {
                $stmt = $this->conn->prepare("INSERT INTO c_users (u_id, username) VALUES(:uID, :username);");
                $stmt->bindparam(":uID",$id);
                $stmt->bindparam(":username",$username);
                $stmt->execute();
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    public function getUserData($username) {
        $user = $this->request("users/".$username.".json");
        return $user['user'];
    }

    public function getProfilePicture($username) {
        $user = $this->request("users/".$username.".json");
        return "https://community.makeroid.io".$user['user']['avatar_template'];
    }

    public function getId($username) {
        $user = $this->request("users/".$username.".json");
        return $user['user']['id'];
    }

    public function getTrustLevel($username) {
        $user = $this->request("users/".$username.".json");
        return $user['user']['trust_level'];
    }

    public function getTrustLevelRequirements($id) {
        $tl3_requirements = $this->request("admin/users/".$id.".json");
        if ($tl3_requirements['tl3_requirements']) {
            return $tl3_requirements['tl3_requirements'];
        } else {
            return false;
        }
    }
}

?>

为什么$ USER和$ COMMUNITY没有共享?

1 个答案:

答案 0 :(得分:0)

我最后通过设置 core.php

来修复
<?php
require_once(ROOTPATH.'/../classes/user.php');
$USER = new USER();

require_once(ROOTPATH.'/../classes/community.php');
$COMMUNITY = new COMMUNITY();

好像没有得到正确的文件