forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional_interfaces.phpt
77 lines (68 loc) · 2.63 KB
/
optional_interfaces.phpt
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
76
77
--TEST--
Optional interfaces work
--FILE--
<?php
interface ExistingInterface {}
class ImplementingOptionalInterface implements ?ExistingInterface {}
class SkippingOptionalInterface implements ?NonExistantInterface {}
class MultipleOptionalsExistingFirst implements ?ExistingInterface, ?NonExistantInterface {}
class MultipleOptionalsExistingLast implements ?NonExistantInterface, ?ExistingInterface {}
class MixedOptionalFirst implements ?NonExistantInterface, ExistingInterface {}
class MixedOptionalLast implements ExistingInterface, ?NonExistantInterface {}
interface ExtendingExistingOptional extends ExistingInterface {}
interface ExtendingNonexistantOptional extends ?NonExistantInterface {}
class ImplementsInheritedExisting implements ExtendingExistingOptional {}
class ImplementsInheritedSkipped implements ExtendingNonexistantOptional {}
$classes = [
ImplementingOptionalInterface::class,
SkippingOptionalInterface::class,
MultipleOptionalsExistingFirst::class,
MultipleOptionalsExistingLast::class,
MixedOptionalFirst::class,
MixedOptionalLast::class,
ImplementsInheritedExisting::class,
ImplementsInheritedSkipped::class,
];
foreach ($classes as $class) {
echo "$class\n";
echo ' class implements:'.implode(', ', class_implements($class))."\n";
echo ' object implements:'.implode(', ', class_implements(new $class))."\n";
}
$interfaces = [
ExtendingExistingOptional::class,
ExtendingNonexistantOptional::class,
];
foreach ($interfaces as $interface) {
echo "$interface\n";
echo ' interface extends:'.implode(', ', class_implements($class))."\n";
}
?>
--EXPECT--
ImplementingOptionalInterface
class implements:ExistingInterface
object implements:ExistingInterface
SkippingOptionalInterface
class implements:
object implements:
MultipleOptionalsExistingFirst
class implements:ExistingInterface
object implements:ExistingInterface
MultipleOptionalsExistingLast
class implements:ExistingInterface
object implements:ExistingInterface
MixedOptionalFirst
class implements:ExistingInterface
object implements:ExistingInterface
MixedOptionalLast
class implements:ExistingInterface
object implements:ExistingInterface
ImplementsInheritedExisting
class implements:ExtendingExistingOptional, ExistingInterface
object implements:ExtendingExistingOptional, ExistingInterface
ImplementsInheritedSkipped
class implements:ExtendingNonexistantOptional
object implements:ExtendingNonexistantOptional
ExtendingExistingOptional
interface extends:ExtendingNonexistantOptional
ExtendingNonexistantOptional
interface extends:ExtendingNonexistantOptional