Re: [RFC][DISCUSSION] Allow default value in list() syntax
| From: | Andreas Hennings | Date: | Sat, 12 Aug 2017 00:37:42 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Allow default value in list() syntax | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100190@lists.php.net to get a copy of this message | ||
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:
> You 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
>