-
Notifications
You must be signed in to change notification settings - Fork 800
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
PHP 7.2: Warning: count(): Parameter must be an array or an object that implements Countable in... #8420
Comments
I couldn't duplicate this either with the info provided. The warning comes from https://github.com/WordPress/WordPress/blob/4.9.1/wp-includes/post-template.php#L284 which uses the global [Edit: Specifically looked at 7.0, not 7.1/7.2] |
I could witness this message in my |
fwiw we have an ongoing master-issue tackling several reports of nuances with PHP 7.2 and Jetpack's code: Also, we have a PR for introducing PHP 7.2 runs for unit tests in Travis... This PR has a few commits addressing some pieces of code in Jetpack that would error on PHP 7.2: The problem is that the errors coming from core remain to be thrown in that branch when run on Travis, so we won't able to have PHP 7.2 passing unit tests until core fixes them. |
Not sure if this is helpful, but I also ran into this. Here's the call stack:
|
Below is the call stack when I get the problem. I'm using the Twenty Seventeen theme with Jetpack 5.7
The following change to the core function get_the_content() eliminates the problem
|
For an explanation of why Jetpack is triggering this, see https://core.trac.wordpress.org/ticket/42814#comment:17 tl;dr: Jetpack is calling a filter outside of the loop which expects to be run within the loop. It's not a bad expectation that it'd work (especially as it's only hit when there's an empty excerpt) but fixing the warnings don't make the underlying function work as expected |
I think #8510 will be more explicit for our part, but there may still be a problem here.
|
The above PR should resolve it if https://core.trac.wordpress.org/ticket/42814#comment:18 also lands. |
Same problem here. |
@Flodu31 For my example, the workaround is to create a Caption ( Excerpt ) for the Attachment. |
Ok thanks, but for me I think it's not the problem because on pages that has no attachment, the problem is present too... |
@Flodu31 If you could include a call stack and more information about where you're seeing it, that would be helpful. Is it on a normal post/page or a CPT? Is there an excerpt for that post/page/CPT already? |
@kraftbj Here's the call stack for a post with no content at all and no excerpt either. In order to get the problem for the page post type it has to have 'excerpt' post type support and have no content, nor an attached image. Jetpack 5.7, Twenty Seventeen 1.4, WordPress 4.9.2
Basically the same as before but I got bored stripping out unnecessary bits of the file names. |
FWIW, Changing this code from this.... if ( empty( $post->post_password ) ) {
$return['excerpt'] = self::get_excerpt( $post->post_content, $post->post_excerpt, $args['max_words'], $args['max_chars'] );
$return['count']['word'] = self::get_word_count( $post->post_content );
$return['count']['word_remaining'] = self::get_word_remaining_count( $post->post_content, $return['excerpt'] );
$return['count']['link'] = self::get_link_count( $post->post_content );
} to this... if ( empty( $post->post_password ) && has_excerpt() ) {
$return['excerpt'] = self::get_excerpt( $post->post_content, $post->post_excerpt, $args['max_words'], $args['max_chars'] );
$return['count']['word'] = self::get_word_count( $post->post_content );
$return['count']['word_remaining'] = self::get_word_remaining_count( $post->post_content, $return['excerpt'] );
$return['count']['link'] = self::get_link_count( $post->post_content );
} Completely resolves the issue for me. |
Getting a report of this in the forums:
Requesting additional information. Update:
|
@pmciano Does my solution that I posted work? Is there something I am overlooking? |
@dsifford thanks for the patch! Unfortunately, I don't think it's going to work, because the code runs inside the There's a candidate PR that we're currently looking at (#8510), but it has the same drawback as your solution: we're ignoring posts that do not have an excerpt. If you have an idea how we can both fix the warning and not exclude a subset of posts, please let us know! |
@zinigor I guess I'm still confused as to how What about just passing edit: Oops, just noticing that the |
@dsifford yes, passing an ID to |
Any update on this issue @zinigor? |
@ollietigs sorry, nothing new at this time. Please follow #8510 for updates, this is where the problem will be fixed. |
put the_content in if condition solve the problem for me |
Another report here: https://wordpress.org/support/topic/warning-php-7-2/#post-10140766 |
I can confirm that @LaQuay's workaround works. Toggling off I have a live site with the issue here: https://joen.com/contact/ Error: Here is the line 284-285 of
Screencast: |
Installing YOAST SEO plugin somehow fixed this issue for me. |
@pabloacastillo Jetpack checks for other plugins and disables some of its functionality in case it could conflict. That could be the case, or maybe you have updated to the newer version simultaneously with installing Yoast. Please let us know here or in support channels if you are still having any problems. |
Thanks pabloacastillo when installing YOAST SEO the problem was solved! |
I have found this with ZF 1.12 running on PHP 7.2 (count files validator). $this->_count = count($this->_files); where $this->_files was NULL; $this->_count = $this->_files !== null ? count($this->_files) : 0; -> did the trick. |
I've been shown a warning message at my add product page post upgrading PHP into 7.2 version, it says "Warning:** count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\E-comm\register_page\add_product.php on line 281 |
@rustydigg918 That looks like a bug in your own code, not Jetpack. |
He tenido el mismo problema: |
Hi Guys This could be due to null values given to WordPress functions. Like If you give null value to wp_trim_excerpt wp_trim_excerpt( $post->post_content ); where $post->post_content = null https://github.com/ThemeFuse/Unyson/issues/3526 Thanks |
Thanks @etwordpress01 ! Exactly, if you're interested in more detail you can click around this PR to see more about the technical details of how it was fixed: #9348 |
Just in case this helps anyone: The Jupiter Wordpress theme is suffering from the same issue. I fixed it with a one-line change in their code, see below.
To fix this for this one specific case, I changed their code in $output .= '<meta property="og:description" content="' . esc_attr( get_the_excerpt() ) . '"/>'; to $output .= '<meta property="og:description" content="' .
esc_attr( has_excerpt($post->ID) ? get_the_excerpt() : wp_trim_excerpt($post->post_content) ) .
'"/>'; |
i did add an extra condition to the line 284 to: |
@abdorabi I would strongly recommend against editing core WordPress files to solve this issue. Instead, it may be best to deactivate all your plugins, one at a time, until you find the plugin that is causing the issue. If that does not help, try switching to one of the default themes to make sure your theme is not the cause of the problem. Once you find what is causing the problem, you can contact the plugin / theme author to ask them to take a look. You can point them to this issue if they need more info, or ask them to take a look at this PR if they want to know how this was fixed for the Jetpack plugin, as an example. |
Thank you @jeherve i will return the wordpress core as it was |
cpbotha I'm struggled with the same code error with Jupiter Theme... but I can't found where is the file I have to edit.. Could you help me? :( Thanks! |
@Irissu I've amended my post above with the correct filename |
so if you've updated your php version above 7.1.9 the 7.2 count() no longer works as a null/empty check, cause the parameter either has to be validated as a collection or an array. |
I will now be locking this conversation, as the issue mentioned here was fixed for the Jetpack plugin in #9348. If you do run into the problem on your site, it is not caused by the Jetpack plugin and the patch I linked to above will not be useful to you; the problem is caused by a different plugin / theme / service on your site, and happens because your server uses PHP 7.2. To find out what plugin or theme is causing the issue, try to deactivate all plugins, one at a time, until the problem disappears. If that does not help, try switching to a different theme for a few minutes. |
Note that WordPress 5.2 will resolve the root issue that led to Jetpack throwing this warning ( https://core.trac.wordpress.org/changeset/44941 ). I'm reopening #8510 to look at better handling the excerpt now that Core more fully supports the expected result of using |
I myself can not replicate this issue.
The error and steps are based on what I collect from various sources:
Steps to reproduce the issue
What I expected
No warning at all in both PHP 5.6.x and PHP 7.x.
What happened instead
The error above with PHP 7.x.
More info
The text was updated successfully, but these errors were encountered: