syntax error, unexpected token “&”¶
Description¶
The &
operator is used in two distinct situations: as the bitwise operator, between two different values; as the reference operator, before a variable.
As the reference operator, it may be used in a method signature, to identify a passed-by-reference argument. It may not be used anymore at call time, for sending an argument nor receiving a value.
The reference operator returns a new reference, and it should be stored in another variable (or any data container). Otherwise, it is
Example¶
<?php
function foo(&$a) {}
// Cannot make a reference at call time
foo(&$c);
// Cannot return a reference at call time
$d = &foo($c);
?>
Solutions¶
Remove the
&
in function call’s argument, and put it in the function signature.Remove the
&
in function call returned value, and put it in the function signature.