Warning: Parameter 2 to function() expected to be a reference, value given in File.php

I recently moved from shared hosting to cloud hosting servers where I had installed newer versions of most of the server software, Apache, PHP, MySQL. After I moved my websites to the new servers, I was not surprised that I received a good number of access errors and that some of the sites did not work properly like they did in the old shared hosting server. One of the errors I got on my wordpress blog was this one:

Warning: Parameter 2 to some_function() expected to be a reference, value given directory/some_file.php on line 298

Of course your own error would refer to a different function, a different file and a different line, but it’s still the same error.

What Does This Error Mean?

This error complains about the second parameter of some_function(). Your own function would be called something different. In my case, my function had two parameters some_function(param1, param2). To find this function, navigate to the file specified in the error message and scroll down to the line number specified.
If it is a wordpress site, you might be able to find the file by going to Appearance > Editor, when you find the file, you can easily search for the function name by pressing CTRL+F on your browser. Otherwise, just use an FTP client like FIleZilla.
When you find the function, you would notice that the second parameter isn’t a variable but PHP expects it to be a variable. It might look something like this some_function($param1, &$param2).

Fixing The Error

This function worked previously in my old servers because I had an old version of PHP. My new servers currently run PHP 7.1 and this is where tthe problem stemmed from. PHP 7.1 changed the way references work. (see: http://php.net/manual/en/language.references.php) the error comes from the & in front of values in functions. Simply remove the & in front of the affected parameter and you’ll be all set. You’ll need to do this for all the functions you’re getting these errors for if it’s more than one.

Stanley Ume

Hi there, my name is Stanley. I spend most of my time learning new technology and doing freelance web design. If this article helped you, please use the comments box below ?. You can connect with me using the social icons below:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *