File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Check that __invoke() works with named parameters
3
+ --FILE--
4
+ <?php
5
+
6
+ class Test {
7
+ public function __invoke ($ a = 'a ' , $ b = 'b ' ) {
8
+ echo "a: $ a, b: $ b \n" ;
9
+ }
10
+ }
11
+
12
+ class 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 ' );
22
+ try {
23
+ $ test (b: 'B ' , c: 'C ' );
24
+ } catch (Error $ e ) {
25
+ echo $ e ->getMessage (), "\n" ;
26
+ }
27
+ echo "\n" ;
28
+
29
+ $ test2 = new Test2 ;
30
+ $ test2 (b: 'B ' , a: 'A ' , c: 'C ' );
31
+ $ test2 (b: 'B ' , c: 'C ' );
32
+ echo "\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 ' );
39
+ try {
40
+ $ test3 (b: 'B ' , c: 'C ' );
41
+ } catch (Error $ e ) {
42
+ echo $ e ->getMessage (), "\n" ;
43
+ }
44
+
45
+ ?>
46
+ --EXPECT--
47
+ a: A, b: B
48
+ a: a, b: B
49
+ Unknown named parameter $c
50
+
51
+ a: A, b: B
52
+ array(1) {
53
+ ["c"]=>
54
+ string(1) "C"
55
+ }
56
+ a: a, b: B
57
+ array(1) {
58
+ ["c"]=>
59
+ string(1) "C"
60
+ }
61
+
62
+ a: A, b: B
63
+ a: a, b: B
64
+ Unknown named parameter $c
You can’t perform that action at this time.
0 commit comments