1--TEST-- 2Basic argument unpacking 3--FILE-- 4<?php 5 6function test(...$args) { 7 var_dump($args); 8} 9 10function test2($arg1, $arg2, $arg3 = null) { 11 var_dump($arg1, $arg2, $arg3); 12} 13 14function getArray($array) { 15 return $array; 16} 17 18function arrayGen($array) { 19 foreach ($array as $element) { 20 yield $element; 21 } 22} 23 24$array = [1, 2, 3]; 25 26test(...[]); 27test(...[1, 2, 3]); 28test(...$array); 29test(...getArray([1, 2, 3])); 30test(...arrayGen([])); 31test(...arrayGen([1, 2, 3])); 32 33test(1, ...[2, 3], ...[4, 5]); 34test(1, ...getArray([2, 3]), ...arrayGen([4, 5])); 35 36test2(...[1, 2]); 37test2(...[1, 2, 3]); 38test2(...[1], ...[], ...[], ...[2, 3], ...[4, 5]); 39 40?> 41--EXPECT-- 42array(0) { 43} 44array(3) { 45 [0]=> 46 int(1) 47 [1]=> 48 int(2) 49 [2]=> 50 int(3) 51} 52array(3) { 53 [0]=> 54 int(1) 55 [1]=> 56 int(2) 57 [2]=> 58 int(3) 59} 60array(3) { 61 [0]=> 62 int(1) 63 [1]=> 64 int(2) 65 [2]=> 66 int(3) 67} 68array(0) { 69} 70array(3) { 71 [0]=> 72 int(1) 73 [1]=> 74 int(2) 75 [2]=> 76 int(3) 77} 78array(5) { 79 [0]=> 80 int(1) 81 [1]=> 82 int(2) 83 [2]=> 84 int(3) 85 [3]=> 86 int(4) 87 [4]=> 88 int(5) 89} 90array(5) { 91 [0]=> 92 int(1) 93 [1]=> 94 int(2) 95 [2]=> 96 int(3) 97 [3]=> 98 int(4) 99 [4]=> 100 int(5) 101} 102int(1) 103int(2) 104NULL 105int(1) 106int(2) 107int(3) 108int(1) 109int(2) 110int(3) 111