mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
d92229d8c7
From an engine perspective, named parameters mainly add three concepts: * The SEND_* opcodes now accept a CONST op2, which is the argument name. For now, it is looked up by linear scan and runtime cached. * This may leave UNDEF arguments on the stack. To avoid having to deal with them in other places, a CHECK_UNDEF_ARGS opcode is used to either replace them with defaults, or error. * For variadic functions, EX(extra_named_params) are collected and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS. RFC: https://wiki.php.net/rfc/named_params Closes GH-5357.
67 lines
914 B
PHP
67 lines
914 B
PHP
--TEST--
|
|
Additional named params are collect into variadics
|
|
--FILE--
|
|
<?php
|
|
|
|
function test($a, string ...$extra) {
|
|
var_dump($a);
|
|
var_dump($extra);
|
|
// Extra named parameters do not contribute toward func_num_args() and func_get_args().
|
|
var_dump(func_num_args());
|
|
var_dump(func_get_args());
|
|
}
|
|
|
|
function test2(&...$refs) {
|
|
foreach ($refs as &$ref) $ref++;
|
|
}
|
|
|
|
test(b: 'b', a: 'a', c: 'c', extra: 'extra');
|
|
echo "\n";
|
|
|
|
test('a', 'b', 'c', d: 'd');
|
|
echo "\n";
|
|
|
|
$x = 0;
|
|
$y = 0;
|
|
test2(x: $x, y: $y);
|
|
var_dump($x, $y);
|
|
|
|
?>
|
|
--EXPECT--
|
|
string(1) "a"
|
|
array(3) {
|
|
["b"]=>
|
|
string(1) "b"
|
|
["c"]=>
|
|
string(1) "c"
|
|
["extra"]=>
|
|
string(5) "extra"
|
|
}
|
|
int(1)
|
|
array(1) {
|
|
[0]=>
|
|
string(1) "a"
|
|
}
|
|
|
|
string(1) "a"
|
|
array(3) {
|
|
[0]=>
|
|
string(1) "b"
|
|
[1]=>
|
|
string(1) "c"
|
|
["d"]=>
|
|
string(1) "d"
|
|
}
|
|
int(3)
|
|
array(3) {
|
|
[0]=>
|
|
string(1) "a"
|
|
[1]=>
|
|
string(1) "b"
|
|
[2]=>
|
|
string(1) "c"
|
|
}
|
|
|
|
int(1)
|
|
int(1)
|