Skip to content

PHP Warning in wp-cache-phase2.php: Array Offset on Null #1014

@h-soneda-sios

Description

@h-soneda-sios

Impacted plugin

Super Cache

Quick summary

On multiple of our sites, we’re seeing this warning :

PHP Warning:  Trying to access array offset on null in ***/plugins/wp-super-cache/wp-cache-phase2.php on line 3024

The relevant code is inside the wp_cache_get_postid_from_comment() function in wp-cache-phase2.php, specifically this line:

$comment['old_comment_approved'] = $comment['comment_approved'];

The surrounding snippet is:

$comment = get_comment( $comment_id, ARRAY_A );
if ( $status != 'NA' ) {
    $comment['old_comment_approved'] = $comment['comment_approved'];
    $comment['comment_approved']     = $status;
}

It appears that get_comment( $comment_id, ARRAY_A ) is returning null, so attempting to access $comment['comment_approved'] triggers the warning. We suspect this happens when the cache‐clear routine runs after a comment has already been deleted.

Would it make sense to add a null‐check for $comment, for example:

if ( ! $comment ) {
    wp_cache_debug( "Comment not found; skipping cache update.", 4 );
    return;
}

before trying to access its array offsets?

Environment when this error occurred:

  • PHP 8.3.8
  • WordPress 6.7
  • WP Super Cache version 2.0.0

Steps to reproduce

I attempted to reproduce the error but wasn’t able to.

This warning may have occurred when deleting a comment with the command (using the --force option)

wp comment delete [comment id] --force

rather than through the admin dashboard.

Site owner impact

Fewer than 20% of the total website/platform users

Severity

Minor

What other impact(s) does this issue have?

No revenue impact

If a workaround is available, please outline it here.

No response

Platform (Simple and/or Atomic)

Simple

Metadata

Metadata

Assignees

Type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions