Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#55442 new defect (bug)

count(): Parameter must be an array or an object that implements Countable in /var/www/html/wp-includes/post-template.php on line 319

Reported by: davidscpl's profile davidscpl Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: template Cc:

Description

Call get_the_content() with no arguments and $post is null. If post is null then this is ran:

 $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );

Associate array has keys with null values. Then on lin3 319 is

if ( $elements['page'] > count( $elements['pages'] ) ) {

Which causes this notice:

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/wp-includes/post-template.php on line 319 Notice: Trying to access array offset on value of type null in /var/www/html/wp-includes/post-template.php on line 325

Change History (4)

#1 @audrasjb
2 years ago

Hello and welcome to WordPress Trac @davidscpl,

I tried to reproduce the issue using the following steps, but it didn't succeed.

  • Using a fresh WordPress 5.9.2 installation
  • Enable WP_DEBUG/WP_DEBUG_DISPLAY constants
  • In one of the Bundled Themes, open the 404.php template and add the following code:
global $post;
var_export( $post );
echo get_the_content();

It echoes NULL (line 2). No PHP warning.

Could you please provide more details on how we can reproduce the issue?

Thanks!

#2 @audrasjb
2 years ago

  • Keywords reporter-feedback added

#3 @davidbaumwald
2 years ago

  • Focuses template added

Related: #42814, #47824.

#4 @SergeyBiryukov
2 years ago

  • Component changed from General to Posts, Post Types
Note: See TracTickets for help on using tickets.