Re: [PHP-DEV] [RFC] [DISCUSSION] Type casting in arraydestructuring expressions

This is only part of a thread. view whole thread
  109307
March 25, 2020 18:46 php@manuelcanga.dev (Manuel Canga)
Hi, Enno,



 ---- En mié, 25 mar 2020 18:53:15 +0100 Enno Woortmann 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