Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#54607 closed defect (bug) (duplicate)

Attempt to read property "comment_ID" on null

Reported by: grzegorzjanoszka's profile Grzegorz.Janoszka Owned by:
Milestone: Priority: normal
Severity: minor Version:
Component: Comments Keywords: php8
Focuses: Cc:

Description (last modified by SergeyBiryukov)

PHP 8 reports warning when we try to access properties of null object.
I see such thing in my WordPress:

FastCGI sent in stderr:
"PHP message: PHP Warning: Attempt to read property "comment_ID" on null in /website/wp-includes/comment-template.php on line 677
PHP message: PHP Warning: Attempt to read property "user_id" on null in /website/wp-includes/comment-template.php on line 28
PHP message: PHP Warning: Attempt to read property "comment_ID" on null in /website/wp-includes/comment-template.php on line 48"
while reading response header from upstream ... request: "GET /website/?replytocom=15958

The code is:

     $comment = get_comment();
     return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );

There is no check if $comment is null.

But when we check the source code of get_comment we see such code:

     if ( ! $_comment ) {
        return null;
     }

So get_comment may return null, but the function get_comment_ID blindly tries to access properties of null objects.

Change History (6)

#1 @hasanuzzamanshamim
3 years ago

I think it should validate again after calling "get_comment" method.

#2 @SergeyBiryukov
3 years ago

  • Description modified (diff)
  • Keywords php8 added
  • Milestone changed from Awaiting Review to 6.0

#3 @johnregan3
3 years ago

There are several places where get_comment() is called, then assumed to be an object (See get_comment_text(), get_comment_time(), etc.)

Should all of these related functions be updated to check for a null $comment value in this ticket? I assume so, but wanted to verify before I start on this task.

Last edited 3 years ago by johnregan3 (previous) (diff)

#4 @iobaid
3 years ago

Not a developer, but searching online for a fix to these errors lead me here.

Wordpress still producing these errors every day.

Is there a fix for it?

Thanks.

#6 @davidbaumwald
2 years ago

  • Milestone 6.0 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #54379.

@grzegorzjanoszka It looks like this should have been resolved by [52818].

Last edited 2 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.