简体   繁体   English

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

[英]Fatal error: Uncaught Error: Call to a member function

I get this error when trying to serve my PHP code from Apache: 当尝试从Apache服务我的PHP代码时出现此错误:

Notice: Undefined variable: COMMUNITY in /var/www/Account/assets/includes/head/nav.php on line 1 注意:未定义的变量:第1行的/var/www/Account/assets/includes/head/nav.php中的COMMUNITY

Fatal error: Uncaught Error: Call to a member function getUser() on null in /var/www/Account/assets/includes/head/nav.php:1 Stack trace: #0 /var/www/Account/assets/includes/head.php(60): include_once() #1 /var/www/Account/cpanel/community.php(3): include('/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} thrown in /var/www/Account/assets/includes/head/nav.php on line 1 致命错误:未捕获错误:在/var/www/Account/assets/includes/head/nav.php:1中,对成员函数getUser()的调用为null:堆栈跟踪:#0 / var / www / Account / assets / includes /head.php(60):include_once()#1 /var/www/Account/cpanel/community.php(3):include('/ var / www / Accoun ...')#2 / var / www /帐户/资产/类/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}抛出第1行上的/var/www/Account/assets/includes/head/nav.php

On XAMPP in Windows it's working, I don't get the error; 在Windows的XAMPP上可以正常工作,但我没有收到错误; but on Linux with Apache doesn't. 但在具有Apache的Linux上却没有。 Both use PHP 7.1 两者都使用PHP 7.1


Content in head.php : 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"); ?>

Content in core.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();

?>

Content in nav.php nav.php中的内容

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

Content in 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;
        }
    }
}

?>

Why the $USER and $COMMUNITY aren't shared? 为什么不共享$ USER和$ COMMUNITY?

I've finally fixed by setting in core.php 我终于通过设置core.php来解决

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

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

It seems like it wasn't getting the proper file 好像没有得到正确的文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未被捕获的错误:在null上调用成员函数prepare() - Fatal error: Uncaught Error: Call to a member function prepare() on null 致命错误:未捕获的错误:在 null 上调用成员函数 dispatch() - Fatal error: Uncaught Error: Call to a member function dispatch() on null Mysql 致命错误:未捕获错误:在布尔值上调用成员函数 fetch() - Mysql Fatal error: Uncaught Error: Call to a member function fetch() on boolean 致命错误:未被捕获的错误:在字符串上调用成员函数prepare() - Fatal error: Uncaught Error: Call to a member function prepare() on string 致命错误:未捕获错误:在 bool 上调用成员函数 fetch() - Fatal error: Uncaught Error: Call to a member function fetch() on bool 致命错误:未捕获的错误:在第9行的布尔值上调用成员函数execute() - Fatal error: Uncaught Error: Call to a member function execute() on boolean on line 9 致命错误:未捕获的错误:在 null 上调用成员函数 format() - Fatal error: Uncaught Error: Call to a member function format() on null PHP 致命错误:未捕获的错误:调用成员 function prepare() - PHP Fatal error: Uncaught Error: Call to a member function prepare() PHP 致命错误:未捕获的错误:在 null 上调用成员 function - PHP Fatal error: Uncaught Error: Call to a member function on null 致命错误:未捕获错误:在 Y 上调用成员 function X - Fatal error: Uncaught Error: Call to a member function X on Y
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM