Re: Re: [RFC] foreach_variable supporting T_LIST

From: Date: Sat, 21 Jul 2012 08:31:18 +0000
Subject: Re: Re: [RFC] foreach_variable supporting T_LIST
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 2012-07-21 12:19, Stas Malyshev wrote:
Hi!
So when I have a function that has a two- or multi-part result then - instead of having one part as the return value and the others by reference - in Python I'd return a tuple.
PHP functions can return arrays and some do - e.g. pathinfo(). But not all of them. Maybe getting more functions return result sets instead of modifying parameters could be one target of that API refactoring people are talking about. However, in some case - e.g. function returning result and maybe error code - tuple may not be that convenient, in most cases you just want the result, and unpacking tuple (or array in PHP) would be additional complication. Oh, I'm talking about my own user functions, not changing any native PHP functionality; things like returning a lat/long pair, or measurement/precision, or - well, pretty much any situation where a function returns an array with a known sequence of elements.
If it can happen once (hence the existence of list in the first place) it can happen several times (in the iteration of a loop). Falling back on reference parameters makes it really hard to get at return values functionally: function foo_wrapper($arg) {
    $t2 = null;
    $t1 = foo($arg, $t2); // $t2 passed by reference
    return [$t1, $t2];
}

Thread (11 messages)

« previous php.internals (#61606) next »