澄清PHP手册;通过引用传递的默认值 [英] Clarification of PHP manual; default values passed by reference
问题描述
由于PHP手册中的不一致(我已经在之前发布过),我只是询问一些澄清。
Due to inconsistencies in the PHP manual (as I've posted about before) I'm just inquiring about some clarification.
功能参数页面( http:// ca2.php.net/manual/en/functions.arguments.php )具有以下注意事项:
The Function Arguments page (http://ca2.php.net/manual/en/functions.arguments.php) has the following note:
注意:从PHP 5起,默认值可以通过引用传递。
Note: As of PHP 5, default values may be passed by reference.
现在,我假设这只是意味着以下语法是可以接受的:
Now, I assume this simply means that the following syntax is acceptable:
function foo(&$bar = null){
// ...
}
然而,再次由于其他不一致,我想知道也许这与其他东西有关。
However, again due to other inconsistencies, I was wondering if perhaps this pertains to something else.
推荐答案
这意味着在PHP 4中,对引用传递的参数使用默认值会导致在解析错误中:
It means that in PHP 4, using a default value for arguments passed by reference would result in a parse error:
Parse error: syntax error, unexpected '=', expecting ')' in ...
在PHP5中,当没有参数被传递时,你的函数将有一个普通的局部变量叫做$ code> $ bar 初始化为 null
。
In PHP5, when no argument is passed, your function will have a normal local variable called $bar
initialized to null
.
应该重写:
注意:从PHP 5开始,函数声明可以定义引用传递参数的默认值。
Note: As of PHP 5, function declarations may define a default value for argument passed by reference.
这篇关于澄清PHP手册;通过引用传递的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!