1

我有以下代码。

        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 行似乎产生了以下错误:

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

我该如何解决?

谢谢

4

1 回答 1

4

$o当您开始将其用作对象时尚未声明,因此只需事先将其设为 stdClass 对象:

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

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

于 2012-05-18T13:27:07.507 回答