• Resolved Kudratullah

    (@mhamudul_hk)


    Hi,
    There’s an undefined variable $item in the beginning of NginCache::validate_dirlist( $list ) function.

    PHP Warning:  Undefined variable $item in /path-to-wp/wp-content/plugins/nginx-cache/nginx-cache.php on line 211
    PHP Warning: Trying to access array offset on value of type null in /path-to-wp/wp-content/plugins/nginx-cache/nginx-cache.php on line 211

    Thanks ??

    • This topic was modified 2 months, 3 weeks ago by Kudratullah.
Viewing 6 replies - 1 through 6 (of 6 total)
  • I see this too – also, there’s a fix that Till Krüss merged today, so guessing we’ll see an update shortly!

    The warnings you’re seeing are due to the fact that the variable $item is not defined properly before it is accessed in the validate_dirlist method of your plugin. Specifically, the code is trying to access the array offset on a variable that may not have been initialized.

    The issue lies in this part of the code in the validate_dirlist method (around line 211):

    if ( $item['type'] === 'f' && strpos( $item, "." ) !== false ) {
        return true;
    }

    The variable $item is being used without being initialized first. To resolve this, you’ll need to iterate through the $list array properly and ensure that $item is defined before trying to access its properties.

    Here’s the corrected version of your validate_dirlist function:

    private function validate_dirlist( $list ) {
    
        foreach ( $list as $item ) {
    
            // Ensure $item is defined and is an array
            if ( ! isset( $item['type'] ) || ! is_array( $item ) ) {
                continue; // Skip invalid or undefined items
            }
    
            // check if it's a file and contains a dot (.)
            if ( $item['type'] === 'f' && strpos( $item['name'], "." ) !== false ) {
                return true;
            }
    
            // validate subdirectories recursively
            if ( $item['type'] === 'd' && ! empty( $item['files'] ) && is_array( $item['files'] ) ) {
                if ( ! $this->validate_dirlist( $item['files'] ) ) {
                    return false;
                }
            }
    
        }
    
        return true;
    }

    Was this ever get patched? I’m still having this error occur quite often and i have the most recent version of the plugin. The error prevents pages from loading and the browser times out. Hopefully Till Krüss can crush this bug.

    [error] 374080#374080: *5 FastCGI sent in stderr: “PHP message: PHP Warning: Undefined variable $item in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Trying to access array offset on value of type null in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Undefined variable $item in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Trying to access array offset on value of type null in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211” while reading response header from upstream, request: “GET /wp-admin/tools.php?page=nginx-cache&message=cache-purged HTTP/2.0”, upstream: “fastcgi://unix:/run/php/php8.1-fpm.sock:”

    Thread Starter Kudratullah

    (@mhamudul_hk)

    coldrealms65

    (@coldrealms65)

    Any word on getting this fix pushed live?

    I tried to put in the updated function but it just crashed. Rather just wait till the dev fixes it ??

    Plugin Author Till Krüss

    (@tillkruess)

    Yep, fixed on GitHub. Will push a release next week.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.