Cannot use object of type stdClass as array_PHP教程
程序员文章站
2022-06-06 19:27:26
...
在我写php是会出现,如下图代码提供错误
Fatal error: Cannot use object of type stdClass as array
在我写php是会出现,如下图代码提供错误
Fatal error: Cannot use object of type stdClass as array
这个问题看提示如果没有经验的朋友可能看不出所以然来,下面我们就来看看我这段代码。
function get_userinfo($id){
$sql ="Select * from @#_debbs where username='$id'";
$result =mysql_query($sql) or die('e');
if( mysql_num_rows($result) ){
$rs = mysql_fetch_object($result);
return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id']);
}else{
return array('参数错误','未知','未知','未知','未知','未知');
}
}
各位看出来是怎么回事了吗?
$rs = mysql_fetch_object($result);
看看上面这或,再看看下面
return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id']);
看出来了没?我上面是以objcect后下面用的时间又用$rs[]数据访问形式,当然就会提示出错哦。
好了问题解决了吧。
推荐阅读
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法
-
PHP“Cannot use object of type stdClass as array”
-
PHP Fatal error: Cannot use object of type stdClass as array in错误_PHP教程
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法,jsonstdclass_PHP教程
-
Cannot use object of type stdClass as array
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法
-
Cannot use object of type stdClass as array_PHP教程
-
PHP JSON出错:Cannot use object of type stdClass as array解决方法,jsonstdclass
-
PHP错误Cannot use object of type stdClass as array in错误的解决办法
-
PHP Fatal error: Cannot use object of type stdClass as array in错误