With the advent of PHP 7, a few webhosts such as SiteGround have made it available on all their shared hosting services and you can find a way to enable it here.
Before you jump the bandwagon though, be aware of the warning they posted on their website:
Please have in mind that even if you’re using an app that supports PHP 7 some of its components like plugins, themes, modules, etc. may have old code that will not work on the latest version. This is why we advise that you always test on a staging environment before you enable it on your live site.
You’ll run into a compatibility issue right away if you use one of the WordPress plugins, W3 Total Cache (W3TC). Right after upgrading to PHP 7, I saw this message on the bottom of every page of my WordPress blog:
Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in WP_PATH/wp-includes/functions.php on line 3297
Actually this error message is misleading, because the real issue is not in functions.php file on line 3297. Instead, you need to go to W3 Total Cache directory within your WordPress installation under wp-content folder and look for a file called TotalCache.php.
The whole path would be:
WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\TotalCache.php
Look for line 512 (highlighted):
/** * Output buffering callback * * @param string $buffer * @return string */ function ob_callback(&$buffer) { global $wpdb;
Remove the ampersand “&” from the code as the following:
function ob_callback($buffer) { global $wpdb;
Here’s the before and after comparison:
Once you’re done changing the code, just clear all the caching and reload your page. This time the error message should disappear.
Update for PHP 7.0.9
With the release of PHP 7.0.9, some people have already encountered more issues with this W3 Total Cache plugin after upgrading.
Typical error messages:
Warning: Parameter 1 to W3_Plugin_Minify::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_Plugin_Cdn::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_PgCache::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_Plugin_Minify::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_Plugin_Cdn::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_PgCache::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_Plugin_Minify::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_Plugin_Cdn::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23 Warning: Parameter 1 to W3_PgCache::ob_callback() expected to be a reference, value given in /wp-content/plugins/w3-total-cache/inc/functions/plugin.php on line 23
Fortunately someone from WordPress forum has already posted a good solution. I personally have not tested this, but at least others have had success implementing the fix.
Just to sum up, you basically need to change make the same code modification as above, but to more files.
If you use Git, you can easily find all these files by running this command:
$ git grep -e 'ob_callback(&$buffer)' -n
And it should list all the filenames you need to update.
WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\PgCache.php WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\BrowserCache.php WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\Cdn.php WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\Minify.php WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\NewRelic.php WP_PATH\wp-content\plugins\w3-total-cache\lib\W3\Plugin\TotalCache.php // *
* You will only see the last file if you haven’t fixed it from the earlier instruction above.
Update each file so that all occurrences of ob_callback(&$buffer)
are replaced with ob_callback($buffer)
.
Finally, it’s worth repeating, backup before you do anything.
If you rather not deal with all these operations yourself, you may want to use some of the fixes and customization like this one (use at your own risk).
References
Modern PHP: New Features and Good Practices
Learning PHP 7: A Pain-Free Introduction to Building Interactive Web Sites
PHP for the Web: Visual QuickStart Guide (5th Edition)
Fixing Warning on HHVM
W3 Total Cache and PHP 7.0.9
Fix and customize W3 Total Cache
yudha says
after a few search, it just make me afraid to switch to php 7. I’m not good with code. so if w3tc still it’s not supported php7. I think i’ll wait 🙁
thanks for the article, cause if i don’t read this, i don’t know what my site will look like.
Ulrich says
Thank you so much! Now it works again!
platt says
You’re welcome Ulrich.
Mahammad Jan-E-Alam says
Thanks….
Angel Kafaliev says
Great
Pavel Chmelar says
Hi,
thank you very much for this article.
Note: I used PSPad and find & replace feature to search through plugin directory locally and then uploaded files online.
Worked like a charm!
Pavel
platt says
Glad to see it worked for you Pavel. Thanks for the tip as well.
Cheers,
platt
Serhii says
Hello,
please, help fix this for PHP 7.0.9
https://wordpress.org/support/topic/w3-total-cache-and-php-709
Thanks!
platt says
Hi Serhii,
I saw that natenate19 already helped you solved the issue with 7.0.9. I’ve updated the post from there as well.
Anita Posch says
Perfect, thanks! But, will I stumble into the same problem after an upgrade of the W3 Total Cache Plugin??
platt says
Hi Anita,
Unfortunately, this is a kludge and will be re-written with a new W3 Total Cache update. But rumor has it that it that the plugin will soon be updated with the permanent fix (I don’t know any dates though).
Manel says
Muchas gracias, un abrazo
Jamal says
Thanks you for fixing this issue. Now my site is charming well
Kim K. says
You are awesome! Thanks so much!!
mrmlk says
amazing!!
thank you so much
Optimator says
Thank you!! Perfect fix 🙂
no-memcache says
Don’t forget that in many cases the the php class “Memcache” is not available and you will need to convert to “Memcached”. So you will also need to update W3TC to use “Memcached” instead of “Memcache”
Martin says
Thanks a bunch!
Works fast and perfect!
platt says
You’re welcome Martin.
Name says
Worked charmly! Thanks
Pradeep M says
Just wanted to say thanks. Worked well on WP v4.22 with W3TC V0.9.4.1.
platt says
You’re welcome Pradeep.
Odingk Prakoso says
thx… thank for your tutorial…
platt says
You’re very welcome Odingk.
Garv says
Yo Yo bro you saved my ton of work. Cause i was searching the issue in the given lines.
Laxmikant Bhumkar says
Thanks, itnota, for detecting very cumbersome edit of W3 Total Cache. We also unaware of its relation with PHP-7 update.
platt says
Thanks Laxmikant. If you saw one of my references, actually I wasn’t the one detecting and solved it. But I want to make sure more people don’t have to go through the headache having their system information is not broadcasted to the whole world after the upgrade.