New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible PHP 7.2 Coding problem - count() parameter #4957

Open
Armarsh opened this Issue May 23, 2018 · 1 comment

Comments

3 participants
@Armarsh

Armarsh commented May 23, 2018

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

WordPress Version: 4.9.6

PHP Version: 7.2.5

MySQL Version: 5.6.39

Server Software: Apache

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

@leepeterson

This comment has been minimized.

Show comment
Hide comment
@leepeterson

leepeterson May 28, 2018

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.

leepeterson commented May 28, 2018

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.

@quasel quasel added the Type: Bug label Aug 31, 2018

@quasel quasel added this to Incoming in Maintenance Releases via automation Aug 31, 2018

@quasel quasel added this to the Pods 2.7.10 milestone Aug 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment