#54607 closed defect (bug) (duplicate)
Attempt to read property "comment_ID" on null
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Comments | Keywords: | php8 |
Focuses: | Cc: |
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)
#2
@
4 years ago
- Description modified (diff)
- Keywords php8 added
- Milestone changed from Awaiting Review to 6.0
#3
@
4 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.
I think it should validate again after calling "get_comment" method.