如何解决thinkphp5报错Call to a member function toArray() on 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就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持后浪云。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/11576/
文章版权归作者所有,未经允许请勿转载。
THE END