Re: [RFC][DISCUSSION] Allow default value in list() syntax

From: Date: Tue, 10 Nov 2015 03:14:56 +0000
Subject: Re: [RFC][DISCUSSION] Allow default value in list() syntax
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-89138@lists.php.net to get a copy of this message
Hey Dan, On 9 November 2015 at 23:24, Dan Ackroyd <danack@basereality.com> wrote: > Hi Reeze, > > On 9 November 2015 at 13:35, reeze <reeze@php.net> 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

« previous php.internals (#89138) next »