Re: [RFC] Skipping parameters take 2
| From: | Andrea Faulds | Date: | Sun, 18 Jan 2015 03:00:53 +0000 |
| Subject: | Re: [RFC] Skipping parameters take 2 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-80721@lists.php.net to get a copy of this message | ||
Hey Marcio,
> On 18 Jan 2015, at 02:22, Marcio Almada <marcio.web2@gmail.com> wrote:
>
> Andrea,
>
>> For consistency with list(), we could also just put nothing:
>>
>> foo($bar, , $baz);
>>
>> Which is like:
>>
>> list($bar, , $baz) = $arr;
>>
>> Thoughts?
>
> Not sure. Do we consider both contexts (list assignment skipping and
> parameter skipping) as assignments? If so, then the consistency
> arguments seems very strong to me.
Not really. But, list() is very function-like in syntax, so it’d make sense to follow its lead for
actual functions.
> Only point against the consistency path is that in the context of
> list() the blank identifier is used to discard a value, while on
> parameter skipping the blank identifier inherits a previously declared
> value.
Yes, I suppose that’s a fair point.
Though if you were to implement a list() clone as a function (purely for the sake of example, you
wouldn’t *actually* want to do this), you might actually do something similar:
function listLike(&$a = 0, &$b = 0, &$c = 0, array $arr) {
if ($a !== 0) {
$a = $arr[0];
}
if ($b !== 0) {
$b = $arr[1];
}
if ($c !== 0) {
$c = $arr[2];
}
}
listLike($bar, 0, $baz, $arr);
list()’s value skipping is a little bit like function argument skipping, in that way, right?
With this list()-like default value syntax, it’d even work the same:
listLike($bar, , $baz, $arr);
…that probably made no sense. But I think there’s a case to be made that since list() follows
this syntax, we should for function calls to.
By the way, while I was opposed to this RFC before, I am seeing its value somewhat when using
badly-designed APIs like json_decode. That said, I’m still not sure I like the RFC concept…
better to make new, improved APIs than add kludges to make bad APIs more usable.
--
Andrea Faulds
http://ajf.me/