Open Armarsh opened 6 years ago
See: https://make.wordpress.org/core/2018/05/17/new-php-polyfills-in-4-9-6/
Specifically:
In PHP 7.2, a warning was introduced when count() is used on an uncountable value. PHP 7.3 will introduce the function is_countable(), which will help prevent this warning by checking that the passed variable is actually countable (the RFC has passed the vote and the function has already been implemented and merged into PHP Core).
Using count() to detect if a value is iterable (able to be passed to a foreach() loop, for example), is also a common practice. However, this will also result in warnings when upgrading to PHP 7.2. In PHP 7.1, the is_iterable() function was introduced to help prevent these warnings.
Issue Overview
When running PHP 7.2 on a high-traffic site with multiple types of custom posts, error logs are showing sporadic warnings:
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /.../wp-includes/post-template.php on line 284
These warnings correspond to searches for specific words or phrases on the site. Only some searches produce the error - but the error can be replicated by repeating the same search. Because or the sporadic nature, I believe that the error is produced if the search results pull up specific Pod custom post templates. This seems to be tied to one or more
the_content
filter hooks.Note that site uses Relevanssi plugins for searches.
See https://wiki.php.net/rfc/counting_non_countables
Expected Behavior
All code within Pods should be compliant with the PHP 7.2 changed standard for count() functions.
Current Behavior
PHP warning message generated in error logs; does not otherwise impact site function. Just creates messy logs.
Steps to Reproduce (for bugs)
May be site specific. I have not been able to reproduce this by simply conducting random searches on the site. Instead I have to look at the time stamp in the error log -- find the corresponding entry in the access log -- and then repeat the identical search as reflectedin the GET request.
Possible Solution
No clue -- and it may not be a bug at all, but something specific to configuration of some of the pods and pod templates.
WordPress Environment
Pods Package Export (helpful!)
Pods-migration.txt
Workaround or Alternate Solution Until Bug is Addressed
Revert to PHP 7.1
Related Issues and/or PRs