|
| 1 | +--TEST-- |
| 2 | +Optional interfaces work |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +interface ExistingInterface {} |
| 7 | + |
| 8 | +class ImplementingOptionalInterface implements ?ExistingInterface {} |
| 9 | +class SkippingOptionalInterface implements ?NonExistantInterface {} |
| 10 | +class MultipleOptionalsExistingFirst implements ?ExistingInterface, ?NonExistantInterface {} |
| 11 | +class MultipleOptionalsExistingLast implements ?NonExistantInterface, ?ExistingInterface {} |
| 12 | +class MixedOptionalFirst implements ?NonExistantInterface, ExistingInterface {} |
| 13 | +class MixedOptionalLast implements ExistingInterface, ?NonExistantInterface {} |
| 14 | + |
| 15 | +interface ExtendingExistingOptional extends ExistingInterface {} |
| 16 | +interface ExtendingNonexistantOptional extends ?NonExistantInterface {} |
| 17 | + |
| 18 | +class ImplementsInheritedExisting implements ExtendingExistingOptional {} |
| 19 | +class ImplementsInheritedSkipped implements ExtendingNonexistantOptional {} |
| 20 | + |
| 21 | +$classes = [ |
| 22 | + ImplementingOptionalInterface::class, |
| 23 | + SkippingOptionalInterface::class, |
| 24 | + MultipleOptionalsExistingFirst::class, |
| 25 | + MultipleOptionalsExistingLast::class, |
| 26 | + MixedOptionalFirst::class, |
| 27 | + MixedOptionalLast::class, |
| 28 | + ImplementsInheritedExisting::class, |
| 29 | + ImplementsInheritedSkipped::class, |
| 30 | +]; |
| 31 | + |
| 32 | +foreach ($classes as $class) { |
| 33 | + echo "$class\n"; |
| 34 | + echo ' class implements '.implode(', ', class_implements($class))."\n"; |
| 35 | + echo ' object implements '.implode(', ', class_implements(new $class))."\n"; |
| 36 | +} |
| 37 | + |
| 38 | +$interfaces = [ |
| 39 | + ExtendingExistingOptional::class, |
| 40 | + ExtendingNonexistantOptional::class, |
| 41 | +]; |
| 42 | + |
| 43 | +foreach ($interfaces as $interface) { |
| 44 | + echo "$interface\n"; |
| 45 | + echo ' interface extends '.implode(', ', class_implements($class))."\n"; |
| 46 | +} |
| 47 | + |
| 48 | +?> |
| 49 | +--EXPECT-- |
| 50 | +ImplementingOptionalInterface |
| 51 | + class implements ExistingInterface |
| 52 | + object implements ExistingInterface |
| 53 | +SkippingOptionalInterface |
| 54 | + class implements |
| 55 | + object implements |
| 56 | +MultipleOptionalsExistingFirst |
| 57 | + class implements ExistingInterface |
| 58 | + object implements ExistingInterface |
| 59 | +MultipleOptionalsExistingLast |
| 60 | + class implements ExistingInterface |
| 61 | + object implements ExistingInterface |
| 62 | +MixedOptionalFirst |
| 63 | + class implements ExistingInterface |
| 64 | + object implements ExistingInterface |
| 65 | +MixedOptionalLast |
| 66 | + class implements ExistingInterface |
| 67 | + object implements ExistingInterface |
| 68 | +ImplementsInheritedExisting |
| 69 | + class implements ExtendingExistingOptional, ExistingInterface |
| 70 | + object implements ExtendingExistingOptional, ExistingInterface |
| 71 | +ImplementsInheritedSkipped |
| 72 | + class implements ExtendingNonexistantOptional |
| 73 | + object implements ExtendingNonexistantOptional |
| 74 | +ExtendingExistingOptional |
| 75 | + interface extends ExtendingNonexistantOptional |
| 76 | +ExtendingNonexistantOptional |
| 77 | + interface extends ExtendingNonexistantOptional |
0 commit comments