Re: Re: Only variables can be passed by reference
| From: | Joe Watkins | Date: | Sat, 06 Dec 2014 09:26:43 +0000 |
| Subject: | Re: Re: Only variables can be passed by reference | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79454@lists.php.net to get a copy of this message | ||
On Sat, 2014-12-06 at 12:03 +0900, Yasuo Ohgaki wrote:
> Hi Rowan,
>
> On Fri, Dec 5, 2014 at 6:12 PM, Rowan Collins <rowan.collins@gmail.com>
> wrote:
>
> > The author of function f1() presumably designed it to apply some change to
> > $v, rather than executing only for its side effects and return value. If
> > the caller wants to ignore this design, they can, but they are not using
> > the function as it was designed. If they pass a function return straight
> > into it, they have no way of capturing the change to $v which the author
> > intended them to see.
>
>
> The value supplied to f1() is return value.
> In languages, there are literal, constant and variable. Return value is
> variable.
> It's better to keep basic rule. IMHO.
>
> $top = array_pop(f2());
>
> is better than
>
> $v = f2();
> $top = array_pop($v);
>
> Is there anyone who likes latter?
> Are there any other languages behave like PHP?
>
> Regards,
>
> --
> Yasuo Ohgaki
> yohgaki@ohgaki.net
A return value that has no references is a temporary variable, you
forgot about temporary variables.
There is a basic, simple rule; temporary variables cannot be used by
reference, which is perfectly logical since there are no references to
temporary variables, that's what makes them temporary.
I don't see the need to change it.
Cheers
Joe