• If you upgrade the PHP version to PHP 7.2, PHP 7.3 or later, the “Hyper Cache Extended” plugin will show the following warning in your WordPress site:

    Warning: Invalid argument supplied for foreach() in /.../wp-content/plugins/hyper-cache-extended/cache.php on line 392

    This is because in PHP 7.2+ the foreach loop no longer supports iterating over null / missing / invalid collections. You need to add a check for null or invalid collection.

    How to fix this issue?

    The best way is to wait for the plugin author to fix the issue, but this did not happen yet. There is not PHP 7.2+ compatible version of the “Hyper Cache Extended” plugin.

    Until an updated plugin is released, use the following fix, directly in the code. Just add a check in the code, using the WP plugin editor:

    Change the lines 391-400 in the original code (causing the PHP warning):

    
    	$hyper_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    	foreach ($hyper_cache['mobile_agents'] as $hyper_a) {
    		if (strpos($hyper_agent, $hyper_a) !== false) {
    			if (strpos($hyper_agent, 'iphone') || strpos($hyper_agent, 'ipod')) {
    				return 'iphone';
    			} else {
    				return 'pda';
    			}
    		}
    	}
    

    Use the following fixed code, compatible with PHP 7.2+:

    
    	$hyper_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
    	$mobile_agents = $hyper_cache['mobile_agents'];
    	if (is_array($mobile_agents) || is_object($mobile_agents)) {
    		foreach ($mobile_agents as $hyper_a) {
    			if (strpos($hyper_agent, $hyper_a) !== false) {
    				if (strpos($hyper_agent, 'iphone') || strpos($hyper_agent, 'ipod')) {
    					return 'iphone';
    				} else {
    					return 'pda';
    				}
    			}
    		}
    	}
    

    This is a screenshot to fix the Hyper Cache Extended plugin incompatibility with PHP 7.2+ directly in the WordPress plugin editor:
    https://prnt.sc/pwrq9k

    This is a pull request, holding the fix in the GitHub plugin mirror repository (plugins.svn.wordpress.org do not support pull requests): https://github.com/wp-plugins/hyper-cache-extended/pull/1

  • The topic ‘Hyper Cache Extended not compatible with PHP 7.2+’ is closed to new replies.