通过引用返回。 return 变量周围的括号

Returning by reference. Parentheses around a return variable

http://php.net/manual/en/function.return.php

You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a)."

我试过这段代码并且有效:

<?php
function &one($param1) {
    $a = $param1 * 2;
    return $a;
}

function &two($param2) {
    $b = $param2 * 2;
    return ($b); //Parentheses around the return variable
}

$_1 =&one(10);
echo $_1 . "</br>"; //outputs "20"

$_2 =&two(10);
echo $_2 . "</br>"; //outputs "20", the same thing

哪个代码示例可以更好地解释它(显示注释在说什么)?

谢谢。

一张图片胜过千言万语。我认为你和文档都是正确的。您应该首先查看版本,因为在编码过程中我们必须记住我们使用的是哪个版本。