WordPress.org

Make WordPress Core

#46148 closed defect (bug) (duplicate)

Error Countable | Post-Template

Reported by: alex0902 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:
PR Number:

Description

Hello,

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 :

<?php
    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
10 months 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
10 months 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.