如何解决thinkphp5报错Call to a member function toArray() on null

最近在开发程序中,出现Call to a member function toArray() on null报错,原来是关联的数据查不到了,返回了空null。

最近在开发程序中,出现Call to a member function toArray() on null
报错,原来是关联的数据查不到了,返回了空null。

所以我们需要在调用toArray()时,要保证对象不为null,再执行toArray()的方法

$result = db($table)->field($fileds)->where($where)->order($order)->select();
return empty($result) ? array(): $result->toArray();

以上这篇如何解决thinkphp5报错Call to a member function toArray() on null就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持芦苇派。

原创文章,作者:ECHO陈文,如若转载,请注明出处:https://www.luweipai.cn/php/1611495269/

  • 1