|
| 1 | +<?php |
| 2 | + |
| 3 | +require "_utils.php"; |
| 4 | + |
| 5 | +$a = 'a'; |
| 6 | +$b = 'b'; |
| 7 | +$c = 'c'; |
| 8 | + |
| 9 | +$array = [$b, 'a','c']; |
| 10 | + |
| 11 | +// Passing arguments as references |
| 12 | +$args = test_variadic_args(); |
| 13 | +assert($args === [], 'Expected no arguments to be returned'); |
| 14 | + |
| 15 | +$args = test_variadic_args($a); |
| 16 | +assert($args === ['a'], 'Expected to return argument $a'); |
| 17 | + |
| 18 | +$args = test_variadic_args($a, $b, $c); |
| 19 | +assert($args === ['a', 'b', 'c'], 'Expected to return arguments $a, $b and $c'); |
| 20 | + |
| 21 | +$args = test_variadic_args(...$array); |
| 22 | +assert($args === ['b', 'a', 'c'], 'Expected to return an array with the array $array'); |
| 23 | + |
| 24 | +assert_exception_thrown('test_variadic_add_required'); |
| 25 | + |
| 26 | +// Values directly passed |
| 27 | +$sum = test_variadic_add_required(1, 2, 3); // 1 |
| 28 | +assert($sum === 6, 'Expected to return 6'); |
| 29 | + |
| 30 | +$count = test_variadic_add_required(11); // 11 |
| 31 | +assert($count === 11, 'Allow only one argument'); |
| 32 | + |
| 33 | +$types = test_variadic_args('a', 1, ['abc', 'def', 0.01], true, new stdClass); |
| 34 | +assert(gettype(end($types[2])) === 'double', 'Type of argument 2 and its last element should be a float of 0.01'); |
| 35 | +assert($types[3], 'Arg 4 should be boolean true'); |
| 36 | +assert($types[4] instanceof stdClass, 'Last argument is an instance of an StdClass'); |
0 commit comments