If you recently upgraded PHP to version 5.3.0 or higher, you have probably encountered a message like this:

Deprecated: Call-time pass-by-reference has been deprecated in filename.php

Use & when you call a function foo(&$var) generates the warning message.

Remember that in 5.3 version of PHP only Call-time pass by reference is deprecated but not Passing by reference.

See the example below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// normal passing by reference
function functionA(&$var) {
    $var++;
}
 
// call-time passing by reference
function functionB($var)
{
    $var++;
}
 
// correct call
functionA($var);
 
// deprecated
functionB(&$var);

If you can’t edit existing code, for example, third-party software, you can use these work-arounds:

  1. Turn off error messages: is always a good idea hide any type of error message in a production site. You can use error_reporting(0) function or if you want you can use the @ symbol before any statement. This is not a good solution of this problem.
  2. Allow call-time pass-by-reference in your php.ini file: in your php.ini file you can set allow_call_time_pass_reference = on but this is a temporary solution only until the next version.

Resources:

, ,