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
|
--TEST--
Behavior of call_user_func_array() with named parameters
--FILE--
<?php
namespace {
$test = function($a = 'a', $b = 'b', $c = 'c') {
echo "a = $a, b = $b, c = $c\n";
};
$test_variadic = function(...$args) {
var_dump($args);
};
call_user_func_array($test, ['A', 'B']);
call_user_func_array($test, [1 => 'A', 0 => 'B']);
call_user_func_array($test, ['A', 'c' => 'C']);
call_user_func_array($test_variadic, ['A', 'c' => 'C']);
try {
call_user_func_array($test, ['d' => 'D']);
} catch (\Error $e) {
echo $e->getMessage(), "\n";
}
try {
call_user_func_array($test, ['c' => 'C', 'A']);
} catch (\Error $e) {
echo $e->getMessage(), "\n";
}
echo "\n";
}
namespace Foo {
call_user_func_array($test, ['A', 'B']);
call_user_func_array($test, [1 => 'A', 0 => 'B']);
call_user_func_array($test, ['A', 'c' => 'C']);
call_user_func_array($test_variadic, ['A', 'c' => 'C']);
try {
call_user_func_array($test, ['d' => 'D']);
} catch (\Error $e) {
echo $e->getMessage(), "\n";
}
try {
call_user_func_array($test, ['c' => 'C', 'A']);
} catch (\Error $e) {
echo $e->getMessage(), "\n";
}
}
?>
--EXPECT--
a = A, b = B, c = c
a = A, b = B, c = c
a = A, b = b, c = C
array(2) {
[0]=>
string(1) "A"
["c"]=>
string(1) "C"
}
Unknown named parameter $d
Cannot use positional argument after named argument
a = A, b = B, c = c
a = A, b = B, c = c
a = A, b = b, c = C
array(2) {
[0]=>
string(1) "A"
["c"]=>
string(1) "C"
}
Unknown named parameter $d
Cannot use positional argument after named argument
|