Fatal error: Call-time pass-by-reference has been removed

Recently, I have few WordPress websites run into White Screen of Death (WSOD) without doing anything by either client or me. The error message can only be observed once WordPress is set to Debug mode. (Change WP_DEBUG to True in wp-config.php).

Fatal error: Call-time pass-by-reference has been removed in /path-to-file/filename.php on line #.

As part of debugging procedure, the problem plugin is temporarily moved from plugin directory. When I try to re-enable the plugin after uploading a newer version, the error message is visible during plugin update in admin panel without causing WSOD. But the plugin itself couldn’t be activated because of the fatal error.

fatal-error-call-time-pass-by-reference

Once the error in located in the source code following the indication, the cause and solution is actually pretty simple.

Here is the code that causes the fatal error.

call-time-passing-by-reference-wrongThe error is caused by the ampersand before “$”. Remove the “&” in front of the “$” will fix the problem.

For example, instead of using:

myCustomFunction(&$arg);        // Deprecated pass-by-reference argument

function myCustomFunction($arg){ 
    ....
}

the proper way is

myCustomFunction($arg);    	// Deprecated pass-by-reference argument

function myCustomFunction(&$arg){ 
    ....
}

To manually fix the error, thoroughly search and replace “&$” with “$” in all php files within the plugin directory.

Although updating the plugin that causes this error to latest version should be the best fix. In my experience, some plugins haven’t come up the fix yet. Therefore, updating the plugin after manual fix should be carefully tested before applying it on live website.

In PHP manual, there is a special note about Passing by Reference

Note: There is no reference sign on a function call – only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that “call-time pass-by-reference” is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.

The actual cause of the pass-by-reference error, is changing of PHP version on hosting server. Because no one made any theme or plugin update to trigger this problem. Some web hosting companies, for example, BlueHost, is phasing out PHP version 5.2 by forcing a PHP upgrade. Some hosting companies may provide option from 5.2 to 5.3, but BlueHost forces a 5.4 upgrade after many notification emails sent to the site owner. As the note described, the deprecated pass-by-reference argument will only causes warning in PHP 5.3, but will lead to fatal error in PHP 5.4 if the code is not written properly.

Here is the quote from BlueHost email notice regarding the PHP upgrade.

PHP, the web programming language, has several different versions and we will be phasing out PHP version 5.2 in the near future as it has been unsupported by its creators for several years now. Your account was found to be using version 5.2 and we have transitioned you to the equivalent option for PHP 5.4, including any extensions you may have been using from our supported list. Should you experience any issues as a result of this transition, please contact a web developer or the developer of the errant software for assistance.