PHP:致命错误:未捕获错误:未定义的类常量'用户'

时间:2017-11-23 18:05:49

标签: php

我收到错误:致命错误:未捕获错误:未定义的类常量'用户' in ... userlist.php; 它是类用户列表的代码:

require_once("/var/www/html/Narkomania.pl/app/objects/user.php");

/* Userlist file */

class UserList
{
    private static $users = array();

    public function addUser($key)
    {
        array_push($users, $key);
    }

    public function removeUser($name)
    {
        foreach ($this->users as $user) {
            if($user->getName() == $name)
            {
                $this->users = array_diff($this->users, array($user));
            }
        }
    }

    public function getUserByName($name)
    {
        foreach ($this->users as $user) {
            if($user->getName() == $name)
            {
                return $user;
            }
        }
    }

    public function userExist($name)
    {
        foreach (self::users as User::$user) {
            if(User::$user->getName() == $name)
            {
                return true;
            }
        }
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

我认为问题在于你如何使用变量(define (base4 n) (let loop ((m n) (acc empty)) (if (< m 4) (cons m acc) (loop (floor (/ m 4)) (cons (remainder m 4) acc))))) (displayln (base4 12)) ; (3 0) (displayln (base4 13)) ; (3 1) (displayln (base4 14)) ; (3 2) (displayln (base4 15)) ; (3 3) (displayln (base4 16)) ; (1 0 0) (displayln (base4 123456)) ; (1 3 2 0 2 1 0 0 0) 。您无法使用$users访问$users,因为它是一个静态变量。因此,您必须始终使用$this->users。另外,更改此方法

self::$users