Re: [RFC][DISCUSSION] Allow default value in list() syntax
| From: | Andreas Hennings | Date: | Thu, 10 Aug 2017 21:22:29 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Allow default value in list() syntax | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-100173@lists.php.net to get a copy of this message | ||
I don't have a strong opinion about the nested list() construct which
is also part of the RFC.
I never had a situation where I wanted this.
On Thu, Aug 10, 2017 at 11:21 PM, Andreas Hennings <andreas@dqxtech.net> wrote:
> Hello list,
>
> I found this RFC, describing a feature I wanted for a long time:
> https://wiki.php.net/rfc/list_default_value
> https://marc.info/?l=php-internals&m=144707619509724
>
> (I don't know how to correctly reply to old emails that are not in my
> inbox, sorry for that. I don't like mailing lists.)
>
> I regularly want this kind of feature when unpacking a string with explode():
>
> list($prefix, $suffix = NULL) = explode(':', $string);
> if (NULL !== $suffix) {
> ...
> }
>
> This is for situations where a string is coming from somewhere, we
> hope it has the format "aaa:bbb", but we cannot be sure.
>
> Sometimes I use a workaround like this:
>
> list($prefix, $suffix) = explode(':', $string . ':');
> if ('' !== $suffix) {
> ...
> }
> Which works, but means a new string will be allocated in memory.
>
> I find the list() with default values to be a decent and
> understandable language feature.
>
> -- Andreas