count(): Parameter must be an array or an object that implements Countable
ThinkPHP
2023-10-14 19:27:53
thinkphp修改php版本后运行项目报错:count(): Parameter must be an array or an object that implements Countable
原因分析在版本php5.6时该写法不会报错,正常运行。但切换版本位7.2时则报错。
错误代码定位区域
count($front['id'])
通过打印$front['id'],发现结果为NULL
解决报错办法
1、优化代码
count($front['id'] ?? [])
2、切换版本
将高版本切换成低版本,如php5.6
报错原因
在php7.2中,count的判断更加严格。

885篇文章
4145人已阅读