版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wm9028/article/details/86573747
Call to a member function toArray() on null
含义就是要保证调用toArray()方法时,要保证对象不为null,再执行toArray()的方法。
遇到的错误代码(tp5)
$product = ConfigParts::field($productInfoField)
->find($cart['product_id'])->toArray();
更正代码,分成两步,第一步先判断查询出来的是否为null,在执行toArray()的操作。
$item = ConfigParts::field($productInfoField)->find($cart["product_id"]);
$product = empty($item) ? array():$item->toArray();