[wp-trac] [WordPress Trac] #54607: Attempt to read property "comment_ID" on null

WordPress Trac noreply at wordpress.org
Fri Dec 10 08:45:20 UTC 2021


#54607: Attempt to read property "comment_ID" on null
-------------------------------+-----------------------------
 Reporter:  Grzegorz.Janoszka  |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Comments           |    Version:
 Severity:  minor              |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 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 677PHP message: PHP Warning:  Attempt to read property "user_id"
 on null in /website/wp-includes/comment-template.php on line 28PHP
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54607>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list