Re: [RFC] [DISCUSSION] Type casting in array destructuring expressions
| From: | Manuel Canga | Date: | Wed, 25 Mar 2020 18:46:31 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Type casting in array destructuring expressions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109307@lists.php.net to get a copy of this message | ||
Hi, Enno,
---- En mié, 25 mar 2020 18:53:15 +0100 Enno Woortmann <enno.woortmann@web.de> escribió
----
> Hi,
>
> I've written the RFC and implemented a first patch concerning the idea
> to allow type casting in array destructuring expressions.
>
>
> The RFC is located at
> https://wiki.php.net/rfc/typecast_array_desctructuring
>
> The patch can be found in MR 5296 located at
> https://github.com/php/php-src/pull/5296
>
>
> Thanks for further feedback!
>
> Cheers, Enno
>
I like your RFC. I hope it is approved. However, I would change your examples. Because, this one:
["now" => (int) $now, "future" => (int) $future] = ["now" =>
"2020", "name" => "2021"];
You could do casting in this way:
["now" => $now, "future" => $future] = array_map('intval',
["now" => "2020", "name" => "2021"] );
If I were you I add examples with mixed types, like:
["address" => (string) $address, "floor" => (int) $floor] =
["address" => "My adress", "floor" => "3"];
I'm sorry my English
Regards
--
Manuel Canga