Home > Backend Development > PHP Tutorial > Why Am I Getting the 'Strict standards: Only variables should be passed by reference' Warning in PHP?

Why Am I Getting the 'Strict standards: Only variables should be passed by reference' Warning in PHP?

DDD
Release: 2024-12-22 12:47:28
Original
641 people have browsed it

Why Am I Getting the

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(..))
Copy after login

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:

  • Modify the method's signature to remove the use of a reference:
function test_arr($a) {
    var_dump($a);
}
Copy after login
  • If modifying the method's signature is not feasible, you can introduce an intermediate variable:
$inter = get_arr();
$el = array_shift($inter);
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template