PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

PHP与SEO 思享 961浏览
摘要:
错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。

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

错误原因:PHP7.2版本之后,count()函数的参数无效时会抛出该warning警告。

php

解决办法

  1. 简单粗暴的方法降级PHP版本。
  2. 如果是使用laravel框架报错的话,composer update一下就可以修复了。
  3. 检查count函数的参数,对参数做好校验判断预防报错。

我比较暴力,直接将参数转化为数组再使用  如:count(a),改为:count((array)a)

推荐阅读

Function get_magic_quotes_gpc() is deprecated报错解决办法

在 PHP 7.4 及更高版本中, get_magic_quotes_gpc() 函数已被弃用。 This means that code using this function will raise a warning or error.以下是解决......

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...

百度自动推送php实现代码

我们知道主动推送有助于搜索引擎抓取和收录网站内容,wordpress或者主流CMS其实已经集成了推送功能。但是如果我们要定期归还,而不是只在发布的时候推一次。这个功能可以通过结合PHP和Pagoda Panel的预定任务来实现。$api = '百度站......