加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

为什么PHP中的引用函数调用已弃用?

发布时间:2020-12-13 13:30:20 所属栏目:PHP教程 来源:网络整理
导读:我写了以下代码: ?php $a1 = "WILLIAM"; $a2 = "henry"; $a3 = "gatES"; echo $a1." ".$a2." ".$a3. "br /"; fix_names($a1,$a2,$a3); echo $a1." ".$a2." ".$a3; function fix_names($n1,$n2,$n3) { $a1 = ucfirst(strtolower($n1)); $a2 = ucfirst(strtol
我写了以下代码:
<?php
    $a1 = "WILLIAM";
    $a2 = "henry";
    $a3 = "gatES";

    echo $a1." ".$a2." ".$a3. "<br />";

    fix_names($a1,$a2,$a3);

    echo $a1." ".$a2." ".$a3;

    function fix_names(&$n1,&$n2,&$n3)
    {
        $a1 = ucfirst(strtolower(&$n1));
        $a2 = ucfirst(strtolower(&$n2));
        $a3 = ucfirst(strtolower(&$n3));

    }

    ?>

我收到了此通知:已弃用:已弃用调用时间传递引用

我需要解释为什么我会收到此通知?为什么在PHP版本5.3.13中,这已被弃用?

这些都记录在PHP Passing by Reference手册页上.具体(加重我的):

Note: There is no reference sign on a function call – only on function
definitions
. Function definitions alone are enough to correctly pass
the argument by reference. As of PHP 5.3.0,you will get a warning
saying that “call-time pass-by-reference” is deprecated when you use &
in foo(&$a);. And as of PHP 5.4.0,call-time pass-by-reference was
removed,so using it will raise a fatal error.

因此,它在PHP 5.3.x中被弃用(并将发出警告),并且在PHP 5.4中将失败.

这就是说,这是一个微不足道的修复.只需更新您的fix_names函数,如下所示:

function fix_names(&$n1,&$n3)
{
    $a1 = ucfirst(strtolower($n1));
    $a2 = ucfirst(strtolower($n2));
    $a3 = ucfirst(strtolower($n3));

}

顺便提一下,5.3.x系列的版本已经很长了,所以如果可能的话,更新到更新的版本(在进行必要的测试之后)是明智的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读