Understanding the Strict Standards Warning: Only Variables Should Be Passed by Reference
When encountering the "Strict standards: Only variables should be passed by reference" warning, it's essential to comprehend the underlying cause and how to resolve it appropriately. This warning arises when an expression is passed by reference rather than a variable, as strict standards require.
In the given code snippet:
$el = array_shift($instance->find(..))
This code triggers the warning because $instance->find(...) is an expression that returns an array, not a variable. This behavior is not intuitive, as one might expect a method returning an array to be handled同樣地 a variable.
To address this error in strict mode, consider the following options:
function test_arr($a) { var_dump($a); }
$inter = get_arr(); $el = array_shift($inter);
By understanding the nature of the warning and applying these solutions, you can resolve the issue effectively and adhere to strict standards.
The above is the detailed content of Why Am I Getting the 'Strict standards: Only variables should be passed by reference' Warning in PHP?. For more information, please follow other related articles on the PHP Chinese website!