Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#46148 closed defect (bug) (duplicate)

Error Countable | Post-Template

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



In some theme, it is possible to have a PHP error "count (): Parameter must be an array or an object that implements Countable", which is due to the code locate "wp-includes / post-template.php: 284" , it is correctable thanks to this code :

    if ( is_array( $pages ) ) {
        if ( $page > count( $pages ) ) // if the requested page doesn't exist
            $page = count( $pages ); // give them the highest numbered page that DOES exist
    } else {
        $page = 0;

Change History (2)

#1 @ayeshrajans
5 years ago

  • Keywords good-first-bug added
  • Severity changed from major to normal

Hi @alex0902 - Welcome to WordPress Trac!
WordPress ships with a polyfill for the is_countable function that PHP 7.3 natively provides. This means all WordPress users, regardless of the PHP version, can now use the is_countable() function.

Although arrays are the most common thing that we call count() on, it's not the only data type. Any objects whose class implements \Countable interface are countable.

If you would like to get to the code contributions to WordPress, this could be a good one to get started with!

#2 @ocean90
5 years ago

  • Keywords good-first-bug removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version trunk deleted

Duplicate of #42814.

Note: See TracTickets for help on using tickets.