2012-05-18 49 views
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号线正在生产以下错误:

Strict standards: Creating default object from empty value

我怎样才能解决呢?

感谢

+1

可能重复[PHP的严格标准:从空值创建默认对象 - 如何解决?](http://stackoverflow.com/questions/1949966/php-strict-standards-creating-default-object-from-空值,如何对修复) –

回答

4

$o当你开始使用它作为一个对象尚未声明,所以只让它作为一个stdClass的对象事先:

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

,或者甚至更好,因为更换$o->user_theme无处不在功能与$user_theme - 因为你的代码似乎并不需要一个特殊的对象,正常的变量就足够了。

相关问题