严格的标准:从空值创建默认对象


Strict standards: Creating default object from empty value

我有以下代码。

        public function get_users_theme($uid)
            {
                    $r = $this->db2->query('SELECT * FROM users_theme WHERE user_id="'.$uid.'" LIMIT 1', FALSE);
                    if ($this->db2->num_rows($r) > 0) {
                            $o->user_theme = new stdClass();
                            $ut = $this->db2->fetch_object($r);
                            foreach($ut as $l=>$s) {
                                    $o->user_theme->$l  = stripslashes($s);
            }
                            return $o->user_theme;
                    } else {
                            return FALSE;
                    }
            }

第 5 行似乎产生以下错误:

严格的标准:从空值创建默认对象

我该如何解决?

谢谢

当你

开始将其用作对象时,$o还没有被声明,所以只需事先将其设为 stdClass 对象:

$o = new stdClass();
$o->user_theme = new stdClass();

或者,更好的是,将该函数中任何地方的$o->user_theme替换为$user_theme - 因为您的代码似乎不需要特殊对象,因此普通变量就足够了。