开发者

call time reference issue with php

开发者 https://www.devze.com 2022-12-09 14:36 出处:网络
function get_arr($arr) { unset($arr[0]); } $arr1开发者_运维百科 = array(1,2); $arr2 = array(1,2); get_arr(&$arr1);
function get_arr($arr)
{
    unset($arr[0]);
}
$arr1开发者_运维百科 = array(1,2);
$arr2 = array(1,2);

get_arr(&$arr1);
get_arr($arr2);
echo count($arr1);
echo count($arr2);

I got :

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of get_arr(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file

But the output is:

12

Which means the call time reference takes effect.

Why the two places output contradictary messages?


Deprecated does not mean non-functional, it's just not recommended.


Call-time pass-by-reference is deprecated, that means it should not be used any more and may not be working in a future version of PHP. It does not mean that it does not work.


It's a warning.

It is just warning you, but at the same time trusts that you know what you are doing.


the source of confusion is that error message is vague, it should read "to get rid of this warning, set allow_call_time_pass_reference to true" instead of "to enable call-time pass-by-reference".

0

精彩评论

暂无评论...
验证码 换一张
取 消