我写了以下代码:
<?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
Passing by Reference手册页上.具体(加重我的):
原文链接:https://www.f2er.com/php/137637.htmlNote: 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系列的版本已经很长了,所以如果可能的话,更新到更新的版本(在进行必要的测试之后)是明智的.