FAQ
Hi internals!

I'd like to open a discussion on the RFC to allow set default values for
list() assignment: https://wiki.php.net/rfc/list_default_value.

What is your idea?

Thanks.

--
Reeze Xia
http://reeze.cn

Search Discussions

  • Dan Ackroyd at Nov 9, 2015 at 3:24 pm
    Hi Reeze,
    On 9 November 2015 at 13:35, reeze wrote:
    Hi internals!

    I'd like to open a discussion on the RFC to allow set default values for
    list() assignment: https://wiki.php.net/rfc/list_default_value.

    What is your idea?
    I find the list construct to be quite magic already. Isn't it possible
    to get the affect that you want without adding anything to the core by
    doing this:

    $defaults = ['default', 'default'];
    $input = [1];

    list($a, $b) = array_replace($defaults, $input);

    I'd find that way easier to understand and explain to junior devs,
    compared to having more functionality added to the 'list' magicness.

    cheers
    Dan
  • Reeze at Nov 10, 2015 at 3:15 am
    Hey Dan,
    On 9 November 2015 at 23:24, Dan Ackroyd wrote:

    Hi Reeze,
    On 9 November 2015 at 13:35, reeze wrote:
    Hi internals!

    I'd like to open a discussion on the RFC to allow set default values for
    list() assignment: https://wiki.php.net/rfc/list_default_value.

    What is your idea?
    I find the list construct to be quite magic already. Isn't it possible
    to get the affect that you want without adding anything to the core by
    doing this:

    $defaults = ['default', 'default'];
    $input = [1];

    list($a, $b) = array_replace($defaults, $input);

    I'd find that way easier to understand and explain to junior devs,
    I saw the contrast way, it is more complex ;-). This seems like a trick.
    Many feature could also be remove,
    such as I refered in RFC: Null coalesce "??" and Ternary Operator "?:"

    And the trick is trick. If you want to unpack nested array.

    list($a, list(list($b))) = $array

    Then you might need a new trick to do that.

    You know we have default for function declaration:
    function func($a='default') {}; and almost all language have the feature,
    it is easier to understand from my perspective.

    compared to having more functionality added to the 'list' magicness.

    cheers
    Dan


    --
    Reeze Xia
    http://reeze.cn

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedNov 9, '15 at 1:35p
activeNov 10, '15 at 3:15a
posts3
users2
websitephp.net

2 users in discussion

Reeze: 2 posts Dan Ackroyd: 1 post

People

Translate

site design / logo © 2021 Grokbase