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

From: Date: Fri, 11 Aug 2017 07:51:33 +0000
Subject: Re: [RFC][DISCUSSION] Allow default value in list() syntax
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-100178@lists.php.net to get a copy of this message
"Andreas Hennings" wrote in message news:CAH0Uv3HQK5wjcd_-9GynMw34H78ZTv09q9bc=yZ10JBbeT=VOA@mail.gmail.com...
On Fri, Aug 11, 2017 at 12:01 AM, Devnuhl Unnamed <devnuhl@gmail.com> wrote:
Would isset($suffix) not suffice here?
You mean like so? list($prefix, $suffix) = explode(':', 'string_without_suffix'); if (!isset($suffix)) { .. } The isset() is too late here, because the list() will already cause an error.
Other concerns fall around list() already being a difficult thing for people to understand
I agree.
I fail to understand what is difficult about it.
The point is that other people have difficulty understanding what is supposed to be a simple feature which is now being expanded to include more options which change its behaviour.
And "destructuring" is a common concept in programming languages. https://www.startpage.com/do/search ?query=destructuring&cat=web&pl=chrome&language=english https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment The following already works in Javascript: [a, b, c, d = 'else'] = ['aa', 'bb', 'cc']; I just tried it in my Chromium console.
That fact that something like this exists in another language is no reason to add it to PHP. -- Tony Marston

« previous php.internals (#100178) next »