Small PHP 7.2 Compatibility Bug of W3 Total Cache

When I upgrade my php to php 7.2, I saw a lot of error log in the log file.

[error] 1502#1502: *625 FastCGI sent in stderr: “PHP message: PHP Warning: count(): Parameter must be an array or an object that implements Countable in /<purged>/wp-content/plugins/w3-total-cache/Cdn_Plugin.php on line 1203” while reading response header from upstream, client: 135.0.172.188, server: www.yinfor.com, request: “GET / HTTP/2.0”, upstream: “fastcgi://unix:/var/run/php/php7.2-fpm.sock:”, host: “www.yinfor.com”

 

It is a bug or error, or just a compatibility issue between php 7.2 and W3 Total Cache.

Based on the the dissus on the WP site, TeroSalminen has a workaround.

Replacing a line in “function get_replaced_urls()” seems to work:

Replace the line
if ( count( $this->_replaced_urls ) ) {
with
if ( $this->_replaced_urls && count($this->_replaced_urls) ) {
and test.

Tags:, ,