#54607 closed defect (bug) (duplicate)
Attempt to read property "comment_ID" on null
| Reported by: | Grzegorz.Janoszka | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Comments | Version: | |
| Severity: | minor | Keywords: | php8 |
| Cc: | Focuses: |
Description (last modified by )
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)
#3
@
5 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I think it should validate again after calling "get_comment" method.