rfc:additional-splat-usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:additional-splat-usage [2014/11/03 22:48] – daverandom | rfc:additional-splat-usage [2021/06/09 16:03] (current) – Status set to inactive for consistency, it was already part of the "Inactive" list patrickallaert | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Additional Usage for the Splat Operator ====== | ====== PHP RFC: Additional Usage for the Splat Operator ====== | ||
- | * Version: | + | * Version: |
* Date: 2014-11-03 | * Date: 2014-11-03 | ||
- | * Author: Chris Wright, daverandom@php.net | + | * Author: Chris Wright, daverandom@php.net, Marcelo Camargo, João Lucchetta |
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 10: | Line 10: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | The argument unpacking operator '' | + | The argument unpacking operator '' |
==== Combining arrays in literal declaration syntax ==== | ==== Combining arrays in literal declaration syntax ==== | ||
Line 22: | Line 22: | ||
</ | </ | ||
- | '' | + | '' |
This RFC proposes allowing the splat operator to be used in array literals as another way to perform this operation: | This RFC proposes allowing the splat operator to be used in array literals as another way to perform this operation: | ||
Line 32: | Line 32: | ||
The new syntax gives equivalent behaviour to the '' | The new syntax gives equivalent behaviour to the '' | ||
+ | |||
+ | As such, the following application of '' | ||
+ | <code php> | ||
+ | $array1 = [" | ||
+ | $array2 = [" | ||
+ | |||
+ | $result = array_merge($array1, | ||
+ | $result2 = [...$array1, | ||
+ | </ | ||
+ | |||
+ | A mixture of applying the splat operator to previously assigned variables and other literal should work just as fine: | ||
+ | <code php> | ||
+ | $array1 = [" | ||
+ | $array2 = [" | ||
+ | |||
+ | $result = array_merge($array1, | ||
+ | $result2 = [...$array1, | ||
+ | </ | ||
+ | |||
+ | The operator should have the same behaviour for numeric and associative arrays. | ||
+ | Multidimensional arrays should not be flattened: the splat operator should have effect in the first level keys only. | ||
+ | |||
+ | === Numeric === | ||
+ | |||
+ | <code php> | ||
+ | $threetofive = [3,4,5]; | ||
+ | $zerotofive = [0, 1, 2, ...$threetofive]; | ||
+ | </ | ||
+ | |||
+ | === Associative === | ||
+ | |||
+ | <code php> | ||
+ | $addressData = [" | ||
+ | $cityData = [" | ||
+ | |||
+ | $propertyData = [" | ||
+ | </ | ||
+ | |||
+ | === Multidimensional === | ||
+ | |||
+ | <code php> | ||
+ | $old_marks = [ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | ]; | ||
+ | |||
+ | $new_marks = [ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | ...$old_marks | ||
+ | ]; /* array(4) { [" | ||
+ | </ | ||
+ | |||
+ | |||
+ | Using the splat operator with elements that are not arrays and not '' | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 37: | Line 104: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | This RFC targets PHP 7. | + | This RFC targets PHP 7.2. |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 73: | Line 140: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | Simple | + | Extend the splat operator usage yes/no? Requires |
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | Nikita Popov has offered to provide an implementation | + | Marcelo Camargo is currently writing a patch for this RFC. |
===== References ===== | ===== References ===== | ||
Line 82: | Line 149: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// |
rfc/additional-splat-usage.1415054911.txt.gz · Last modified: 2017/09/22 13:28 (external edit)