Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#46445 closed defect (bug) (duplicate)

Parameter must be an array or an object that implements Countable

Reported by: sanjeevsetu's profile sanjeevsetu Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: Posts, Post Types Keywords:
Focuses: Cc:


Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\wordpress\wp-includes\post-template.php on line 293

Getting the warning when I use "get_the_excerpt()" in wp_head hook.

Change History (3)

#1 @jorbin
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from assigned to closed

I can't reproduce this with a default theme and no plugins enabled using the following test code on php 7.3.2

add_action( 'wp_head', function(){

It sounds like a plugin or theme is overriding the $pages global and setting it to the wrong object type.

#2 @l3rady
5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

We are seeing our logs fill up with this error since moving to PHP 7.2

The error doesn't happen for normal circumstances but happens when we have people probing our site for vulnerabilities where their query string results in the global $pages being returned as null which isn't countable.

An example query string that triggered it for us is the following: index.php?s=%2Fmodule%2Faction%2Fparam1%2F%24%7B%40print%28eval%28%24_POST%5Bc%5D%29%29%7D decoded as index.php?s=/module/action/param1/${@print(eval($_POST[c]))}

It appears that certain conditions can get Wordpress to result in null for $pages and so the code needs to check that $pages are countable.

#3 @SergeyBiryukov
5 years ago

  • Component changed from General to Posts, Post Types
  • Resolution set to duplicate
  • Status changed from reopened to closed

Hi @sanjeevsetu, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #42814.

Note: See TracTickets for help on using tickets.