rfc:array_unpacking_string_keys

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:array_unpacking_string_keys [2021/01/07 11:31] nikicrfc:array_unpacking_string_keys [2021/02/08 16:00] 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: Accepted
   * 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 43: Line 43:
  
 Keys that are neither integers nor strings continue to throw a ''TypeError''. Such keys can only be generated by ''Traversable''s. 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>
  
 ===== Alternatives ===== ===== Alternatives =====
Line 105: 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.txt · Last modified: 2021/02/09 09:55 by nikic