Re: [RFC][DISCUSSION] Allow default value in list() syntax
| From: | Devnuhl Unnamed | Date: | Thu, 10 Aug 2017 22:01:07 +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-100175@lists.php.net to get a copy of this message | ||
Would isset($suffix) not suffice here? There are several things I've
thought of that would be other alternatives to changing this language
construct, but as I don't have my laptop with me, some of the testing to
confirm behavior will have to wait.
Other concerns fall around list() already being a difficult thing for
people to understand, let alone use properly. Making it look even more like
a function definition would likely exacerbate this.
-Chris
On Aug 10, 2017 16:33, "Sara Golemon" <pollita@php.net> wrote:
On Thu, Aug 10, 2017 at 5:21 PM, Andreas Hennings <andreas@dqxtech.net>
wrote:
> 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 regularly want this kind of feature when unpacking a string with
explode():
>
> list($prefix, $suffix = NULL) = explode(':', $string);
> if (NULL !== $suffix) {
> ...
> }
>
Agreed. This comes up for me every time I want to parse a text file
(including about 30 minutes ago, as it happens).
+1
-Sara