+3 votes
in Programming Languages by (6.4k points)

Today I installed PHP 7.2 on my webserver, but I am getting error "PHP Warning:  count(): Parameter must be an array or an object that implements Countable". Earlier I had PHP 5.6 and never saw this error in the error log. Is it specific to PHP 7.2? How can I fix it.

1 Answer

0 votes
by (26.2k points)

Yes, you will see this error only when you have PHP 7.2. I am not sure about PHP 7.0 and PHP 7.1 as I have not tested them. I was also getting the same error after installing PHP 7.2. I am using CMS 'question2answer'. It seems that if the function count() return NULL, PHP core returns this error. I did the following change in qa-include/app/format.php (line 384) of 'question2answer' to fix the error.


if (count(@$favoritemap['category'])) 


if (@$favoritemap['category'] && count(@$favoritemap['category']))

So, I think the quick fix should be:


if (count(any_variable))


if (any_variable && count(any_variable))