1--TEST--
2Check that __invoke() works with named parameters
3--FILE--
4<?php
5
6class Test {
7    public function __invoke($a = 'a', $b = 'b') {
8        echo "a: $a, b: $b\n";
9    }
10}
11
12class Test2 {
13    public function __invoke($a = 'a', $b = 'b', ...$rest) {
14        echo "a: $a, b: $b\n";
15        var_dump($rest);
16    }
17}
18
19$test = new Test;
20$test(b: 'B', a: 'A');
21$test(b: 'B');
22try {
23    $test(b: 'B', c: 'C');
24} catch (Error $e) {
25    echo $e->getMessage(), "\n";
26}
27echo "\n";
28
29$test2 = new Test2;
30$test2(b: 'B', a: 'A', c: 'C');
31$test2(b: 'B', c: 'C');
32echo "\n";
33
34$test3 = function($a = 'a', $b = 'b') {
35    echo "a: $a, b: $b\n";
36};
37$test3(b: 'B', a: 'A');
38$test3(b: 'B');
39try {
40    $test3(b: 'B', c: 'C');
41} catch (Error $e) {
42    echo $e->getMessage(), "\n";
43}
44
45?>
46--EXPECT--
47a: A, b: B
48a: a, b: B
49Unknown named parameter $c
50
51a: A, b: B
52array(1) {
53  ["c"]=>
54  string(1) "C"
55}
56a: a, b: B
57array(1) {
58  ["c"]=>
59  string(1) "C"
60}
61
62a: A, b: B
63a: a, b: B
64Unknown named parameter $c
65