-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathinvokable_automatic_implementation.phpt
More file actions
75 lines (62 loc) · 1.54 KB
/
invokable_automatic_implementation.phpt
File metadata and controls
75 lines (62 loc) · 1.54 KB
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
73
74
75
--TEST--
Invokable is automatically implemented
--FILE--
<?php
/* Basic auto-implementation */
class Test {
public function __invoke(): string {
return "foo";
}
}
var_dump(new Test instanceof Invokable);
var_dump((new ReflectionClass(Test::class))->getInterfaceNames());
/* Inheritance: child inherits Invokable from parent */
class Child extends Test {}
var_dump(new Child instanceof Invokable);
var_dump((new ReflectionClass(Child::class))->getInterfaceNames());
/* Child overrides __invoke */
class ChildOverride extends Test {
public function __invoke(): string {
return "bar";
}
}
var_dump(new ChildOverride instanceof Invokable);
/* Arbitrary signature: different params and return type */
class Adder {
public function __invoke(int $a, int $b): int {
return $a + $b;
}
}
var_dump(new Adder instanceof Invokable);
/* No params, no return type */
class NoSig {
public function __invoke() {}
}
var_dump(new NoSig instanceof Invokable);
/* Explicit + implicit: class has __invoke and writes implements Invokable */
class ExplicitAndImplicit implements Invokable {
public function __invoke(): void {}
}
var_dump(new ExplicitAndImplicit instanceof Invokable);
/* Should appear only once in the interface list */
var_dump((new ReflectionClass(ExplicitAndImplicit::class))->getInterfaceNames());
?>
--EXPECT--
bool(true)
array(1) {
[0]=>
string(9) "Invokable"
}
bool(true)
array(1) {
[0]=>
string(9) "Invokable"
}
bool(true)
bool(true)
bool(true)
bool(true)
array(1) {
[0]=>
string(9) "Invokable"
}