Only variable references should be returned by reference - Codeigniter
This error message in Codeigniter indicates that you are attempting to return a variable by reference, but only variable references can be returned by reference.
This PHP error indicates that you are attempting to return a value by reference, but PHP only allows returning references to actual variables.
In PHP, you can return a reference to a variable by prefixing the variable name with an ampersand (&) in the function definition. However, you can only return a reference to a variable, not to a literal, an expression, or the result of a function call.
Here's an example of correct usage:
Fixing the "Only variable references should be returned by reference" error
<?php
function &get_value()
{
$value = 10;
return $value;
}Here's an example of incorrect usage that would trigger the error message:
Example of the "Only variable references should be returned by reference" error
<?php
function &get_value()
{
return 5 + 10; // cannot return a reference to an expression
}If you are seeing this error, it means you are attempting to return a reference to something that is not a variable. This commonly occurs in CodeIgniter applications when developers accidentally return references to method calls, temporary expressions, or literals. To fix the error, modify your code to ensure you are only returning references to actual variables.