thinkphp - thinkphp5 返回数组提示variable type error: array

修改该异常方法,将是数组的返回进行json_encode

 

在获得$content的下一行增加下面一行:

 if(is_array($content)) $content = json_encode($content);

 

修改结果:

/**
 * 获取输出数据
 * @access public
 * @return mixed
 */
public function getContent()
{
    if (null == $this->content) {
        $content = $this->output($this->data);
        if(is_array($content)) $content = json_encode($content);
        if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
            $content,
            '__toString',
        ])
        ) {
            throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
        }

        $this->content = (string) $content;
    }

    return $this->content;
}

 

posted @ 2019-01-29 15:03  德丽莎·阿波卡利斯  阅读(1172)  评论(0编辑  收藏  举报