Opened 6 years ago
Closed 6 years ago
#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: |
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)
Note: See
TracTickets for help on using
tickets.
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 theis_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!