简体   繁体   English

尝试获取PHP中非对象的属性

[英]Trying to get property of non-object in PHP

I'm working with PHP and get error message: 我正在使用PHP并收到错误消息:

Notice: Trying to get property of non-object in D:\\xampp\\htdocs\\gmbr\\fw\\model\\UserModel.php on line 234 注意:尝试在第234行的D:\\ xampp \\ htdocs \\ gmbr \\ fw \\ model \\ UserModel.php中获取非对象的属性

This is my code: 这是我的代码:

# Static user
public static function is_admin()
{
    return self::$auth->admin?true:false; // <<- This line 234
}

public static function username()
{
    return self::$auth->username;
}

Probably what's going on is that the $auth object isn't initialized yet when your method is called. 可能发生的情况是,调用您的方法时,尚未初始化$ auth对象。

Use a var_dump(self::$auth) to see what's going on. 使用var_dump(self :: $ auth)看看发生了什么。

If this is the case, I would use a Singleton design pattern with $auth, Running a self::getAuth() instead of self::$auth. 如果是这种情况,我将使用具有$ auth的Singleton设计模式,运行self :: getAuth()而不是self :: $ auth。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM