插件窝 干货文章 php线上项目中报错:Warning: count():Parameter must be an array or an object that implements Countable的解决方案

php线上项目中报错:Warning: count():Parameter must be an array or an object that implements Countable的解决方案

php 报错 853    来源:插件窝    2019-10-15

报错信息:Warning: count(): Parameter must be an array or an object that implements Countable

开发的时候发现线下运行没问题,到了线上就报这个错误,测试发现php版本不一样导致的




这主要是7.2版本更新,部分方法变得更加严谨了 当传递一个无效参数的时候,count()函数会抛出warning的警告,


php7.2版本中count()方法不能传除了数组和对象之外的类型参数




解决办法




1.如果是使用laravel框架报错的话,composer update一下就可以修复了。




2.不要传递无效的参数执行count,做好校验判断预防报错。