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

WordPress Trac noreply at wordpress.org
Sat Dec 11 00:18:42 UTC 2021


#54607: Attempt to read property "comment_ID" on null
-------------------------------+---------------------
 Reporter:  Grzegorz.Janoszka  |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  6.0
Component:  Comments           |     Version:
 Severity:  minor              |  Resolution:
 Keywords:  php8               |     Focuses:
-------------------------------+---------------------
Changes (by SergeyBiryukov):

 * keywords:   => php8
 * milestone:  Awaiting Review => 6.0


Old description:

> 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.

New description:

 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.

--

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


More information about the wp-trac mailing list