rfc:array_unpacking_string_keys

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:array_unpacking_string_keys [2021/01/07 11:24] – created nikicrfc:array_unpacking_string_keys [2021/02/09 09:55] (current) nikic
Line 2: Line 2:
   * Date: 2021-01-07   * Date: 2021-01-07
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
-  * Status: Under Discussion+  * Status: Implemented
   * Proposed Version: PHP 8.1   * Proposed Version: PHP 8.1
   * Implementation: https://github.com/php/php-src/pull/6584   * Implementation: https://github.com/php/php-src/pull/6584
Line 40: Line 40:
 // Which is [0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5, 5 => 6] // Which is [0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5, 5 => 6]
 // where the original integer keys have not been retained. // where the original integer keys have not been retained.
 +</PHP>
 +
 +Keys that are neither integers nor strings continue to throw a ''TypeError''. Such keys can only be generated by ''Traversable''s.
 +
 +Traversables may also generate integral string keys, which are canonicalized to integer keys by arrays. Such keys will be treated the same way as integer keys and renumbered:
 +
 +<PHP>
 +function gen() {
 +    yield "3" => 1;
 +    yield "2" => 2;
 +    yield "1" => 3;
 +}
 +var_dump([...gen()]); // [1, 2, 3]
 </PHP> </PHP>
  
Line 103: Line 116:
 ===== Vote ===== ===== Vote =====
  
-Yes/No.+Voting started on 2021-01-25 and ended on 2021-02-08. 
 + 
 +<doodle title="Allow string keys in array unpacking?" auth="nikic" voteType="single" closed="true"> 
 +   Yes 
 +   No 
 +</doodle>
  
rfc/array_unpacking_string_keys.1610018658.txt.gz · Last modified: 2021/01/07 11:24 by nikic