Re: [RFC][DISCUSSION] Allow default value in list() syntax
| From: | Björn Larsson | Date: | Mon, 14 Aug 2017 09:35:02 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Allow default value in list() syntax | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100208@lists.php.net to get a copy of this message | ||
Den 2017-08-12 kl. 02:37, skrev Andreas Hennings:
This is true, I remember having done it in the past. I still think it would be nice and feel natural to have the default values directly built into the list construct. It would be a bit faster, because it does not have to allocate a new temporary array. Whether this difference matters depends on the case. In my own philosophy, every code that I write to be reusable, could at some point be used in a situation where it is repeated a lot, and thus has a performance impact. So for my taste, it does matter. This said, I understand it not having the greatest priority. On Fri, Aug 11, 2017 at 7:46 PM, Andreas Treichel <gmblar@gmail.com> wrote:[$foo, $bar, $foobar = 1337] = explode(':', 'foo:bar'); is more readable. I find it a small but nice addition that doesn't clutter the language. r//BjörnYou can merge the result with default values like this: [$foo, $bar, $foobar] = explode(':', 'foo:bar') + [23, 42, 1337]; var_dump($foo, $bar, $foobar); -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php One could argue that: