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