Error Message "Strict Standards: Only Variables Should Be Passed by Reference"
When using array_shift(), it may report a strict standards warning if the argument passed is the result of a function call. This behavior is seemingly inconsistent, as it does not always trigger the warning.
Consider the following code:
$el = array_shift($instance->find(..))
In this example, the warning is raised because the find() method is not a variable. However, the following code does not produce a warning:
function get_arr(){ return array(1, 2); } $el = array_shift(get_arr());
To understand this behavior, let's analyze a different code snippet:
error_reporting(E_STRICT); class test { function test_arr(&$a) { var_dump($a); } function get_arr() { return array(1, 2); } } $t = new test; $t->test_arr($t->get_arr());
This code generates a strict standards warning because the $t->get_arr() method is not a variable and is being passed by reference. This behavior is counterintuitive because the method returns an array value.
To avoid this error in strict mode, either change the method signature to avoid using a reference or use an intermediate variable:
function test_arr($a) { var_dump($a); } $inter = get_arr(); $el = array_shift($inter);
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3