On 06/12/2014 11:00, Christoph Becker wrote:
Yasuo Ohgaki wrote:

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?
IMHO, the first snippet is confusing (the second as well, if $v is not
used in the following code).  Actually, you don't want to pop the top of
the stack, but you want to simply get it without altering the stack at
all.  Therefore it seems reasonable to use a function called array_top()
(or so) which takes its argument by value.

I think this hits the nail on the head: most times when you're trying to pass a literal or return to a by-ref parameter, it's because the function you're using isn't actually the right fit for what you're trying to do - either because it's badly designed (arguably the case with stream_select()) or because you're using it for a purpose it wasn't intended for (e.g. array_pop() if you're not going to use the rest of the stack).

For user-defined functions, one reaction to the E_STRICT notice might be to realise that you don't actually need a by-ref parameter there anyway, so you can remove the & in the declaration, and everything's fine. For internal functions, it may mean that we're lacking something useful (e.g. accessing first and last elements of arrays without side-effects).

--
Rowan Collins
[IMSoP]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to