Hey Marcio,

> On 18 Jan 2015, at 02:22, Marcio Almada <marcio.w...@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/





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

Reply via email to