"Only variables should be passed by reference" in PHP — What It Means and How to Fix It

What the PHP error "Only variables should be passed by reference" means and how to fix it.

Published November 1, 2026

"Only variables should be passed by reference" occurs when a function expecting a reference parameter (like sort(), which modifies in place) is given a non-variable expression.

Key points

  • Assign the expression to a variable first, then pass that variable to the function
More PHP articles