• Resolved Tessa Watkins

    (@tessachu)


    Hello there! I’m receiving this message in our logs:
    [13-Aug-2020 11:54:30 America/New_York] PHP Notice: Undefined offset: 0 in D:\home\site\wwwroot\wp-content\plugins\wp-fastest-cache\inc\cache.php on line 865

    Peaking at the cache.php file in your plugin, this is the function:

    public function fix_pre_tag($content, $buffer){
    			if(preg_match("/<pre[^\>]*>/i", $buffer)){
    				preg_match_all("/<pre[^\>]*>((?!<\/pre>).)+<\/pre>/is", $buffer, $pre_buffer);
    				preg_match_all("/<pre[^\>]*>((?!<\/pre>).)+<\/pre>/is", $content, $pre_content);
    				if(isset($pre_content[0]) && isset($pre_content[0][0])){
    					foreach ($pre_content[0] as $key => $value){
    						/*
    						location ~ / {
    						    set $path /path/$1/index.html;
    						}
    						*/
    						$pre_buffer[0][$key] = preg_replace('/\$(\d)/', '\\\$$1', $pre_buffer[0][$key]);
    						$content = preg_replace("/".preg_quote($value, "/")."/", $pre_buffer[0][$key], $content);
    					}
    				}
    			}
    			return $content;
    		}

    And this is the line 865:
    $pre_buffer[0][$key] = preg_replace('/\$(\d)/', '\\\$$1', $pre_buffer[0][$key]);

    Since reading this article, would it make sense to change the if-statement from this:
    if(isset($pre_content[0]) && isset($pre_content[0][0]))

    to this?
    if((isset($pre_content[0]) || array_key_exists(0,$pre_content)) && (isset($pre_content[0][0])) || array_key_exists(0,$pre_content[0])))

    Because it seems odd to me that isset($pre_content[0]) would evaluate to true but then suddenly be an undefined offset within the foreach loop. But that article I linked above may explain why this is happening. Thank you!

    —-

    Actually, now that I look harder, I notice that the line being flagged is referencing the $pre_buffer array, not $pre_content, so maybe the if-statement should be this:
    if(isset($pre_content[0]) && isset($pre_content[0][0]) && isset($pre_buffer[0]))

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Undefined offset 0 in \inc\cache.php’ is closed to new replies.