Cannot pass parameter %d by reference
Description
When a parameter is set to be passed by reference, there is a & character before its name. In that case, the argument must be a data container, such as a variable, a property, a static property, an array index, but it cannot be a literal value, a constant, or the result of an expression.
Example
<?php
function foo(&$a) {}
// invalid cases
foo(1);
foo(1 + 2);
const A = 1;
foo(A);
class X {
const B = 2;
}
foo(X::B);
?>
Literal Examples
- Cannot pass parameter 1 by reference
Alternatives
- Store the value in a variable and passe the variable.
- Remove the reference in the method signature.
Related error messages
- %s%s%s():-argument-#%d%s%s%s-must-be-passed-by-reference,-value-given
- parameter-%d-must-be-passed-by-reference
In more recent PHP versions, this error message is now :ref:%s():-argument-#%d%s%s%s-cannot-be-passed-by-reference.