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)."

I tried this piece of code and it works:

Code:

<?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

What code example would explain it better (show what the note is talking about)?

Thanks.
CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 238 تاريخ : شنبه 1 ارديبهشت 1397 ساعت: 18:29