rfc:spread_operator_for_array

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:spread_operator_for_array [2019/04/21 19:39] jhdxrrfc:spread_operator_for_array [2019/05/09 11:14] – Accepted nikic
Line 3: Line 3:
   * Date: 2018-10-13   * Date: 2018-10-13
   * Author: CHU Zhaowei, jhdxr@php.net   * Author: CHU Zhaowei, jhdxr@php.net
-  * Status: Voting+  * Status: Accepted
   * First Published at: http://wiki.php.net/rfc/spread_operator_for_array   * First Published at: http://wiki.php.net/rfc/spread_operator_for_array
  
Line 84: Line 84:
 ===== Q & A ===== ===== Q & A =====
 ==== Advantages over array_merge ==== ==== Advantages over array_merge ====
-  - Spread operator should have a better performance than ''array_merge''. It'becuase not only that spread operator is a language structure while ''array_merge'' is a function call, but also compile time optimiztion can be performaned for constant arrays. +  - Spread operator should have a better performance than ''array_merge''. It'because not only that spread operator is a language structure while ''array_merge'' is a function call, but also compile time optimization can be performant for constant arrays. 
-  - ''array_merge'' only supports array, while spread operator also supportes objects implementing ''Traversable''+  - ''array_merge'' only supports array, while spread operator also supports objects implementing ''Traversable''
-<code php>+<PHP>
 // Before // Before
 array_merge(iterator_to_array($iter1), iterator_to_array($iter2)) array_merge(iterator_to_array($iter1), iterator_to_array($iter2))
  
-// Or to generalise to all iterables +// Or to generalize to all iterables 
-array_merge( is_array($iter1) ? $iter1 : iterator_to_array($iter1), +array_merge( 
-is_array($iter2) ? $iter2 : iterator_to_array($iter2) )+  is_array($iter1) ? $iter1 : iterator_to_array($iter1), 
 +  is_array($iter2) ? $iter2 : iterator_to_array($iter2) 
 +)
  
 // After (handles both cases) // After (handles both cases)
Line 98: Line 100:
  
 //Thanks Rowan for providing this example //Thanks Rowan for providing this example
-</code>+</PHP>
  
 ==== ... should be preserved for other use (e.g. map concat) ==== ==== ... should be preserved for other use (e.g. map concat) ====
Line 114: Line 116:
 Voting started 2019-04-22 and ends 2019-05-06. A 2/3 majority is required. Voting started 2019-04-22 and ends 2019-05-06. A 2/3 majority is required.
  
-<doodle title="Support spread operator for array definition in PHP 7.4?" auth="jhdxr" voteType="single" closed="false">+<doodle title="Support spread operator for array definition in PHP 7.4?" auth="jhdxr" voteType="single" closed="true">
    * Yes    * Yes
    * No    * No
rfc/spread_operator_for_array.txt · Last modified: 2019/05/13 12:45 by nikic