|
| 1 | +<?php // lint >= 8.0 |
| 2 | + |
| 3 | +namespace Bug14457; |
| 4 | + |
| 5 | +abstract class ParentClass { |
| 6 | + public function foo(): int { |
| 7 | + return 42; |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +abstract class ChildClass extends ParentClass { |
| 12 | + abstract public function foo(): int; |
| 13 | +} |
| 14 | + |
| 15 | +// OK: abstract method overriding abstract method |
| 16 | +abstract class AbstractParent { |
| 17 | + abstract public function bar(): int; |
| 18 | +} |
| 19 | + |
| 20 | +abstract class AbstractChild extends AbstractParent { |
| 21 | + abstract public function bar(): int; |
| 22 | +} |
| 23 | + |
| 24 | +// OK: non-abstract method overriding non-abstract method |
| 25 | +abstract class ConcreteParent { |
| 26 | + public function baz(): int { |
| 27 | + return 1; |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +abstract class ConcreteChild extends ConcreteParent { |
| 32 | + public function baz(): int { |
| 33 | + return 2; |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// OK: non-abstract method overriding abstract method (implementing it) |
| 38 | +abstract class AbstractParent2 { |
| 39 | + abstract public function qux(): int; |
| 40 | +} |
| 41 | + |
| 42 | +abstract class ConcreteChild2 extends AbstractParent2 { |
| 43 | + public function qux(): int { |
| 44 | + return 1; |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +// abstract static method overriding non-abstract static method |
| 49 | +abstract class StaticParent { |
| 50 | + public static function staticMethod(): int { |
| 51 | + return 1; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +abstract class StaticChild extends StaticParent { |
| 56 | + abstract public static function staticMethod(): int; |
| 57 | +} |
| 58 | + |
| 59 | +// abstract protected method overriding non-abstract protected method |
| 60 | +abstract class ProtectedParent { |
| 61 | + protected function protectedMethod(): int { |
| 62 | + return 1; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +abstract class ProtectedChild extends ProtectedParent { |
| 67 | + abstract protected function protectedMethod(): int; |
| 68 | +} |
| 69 | + |
| 70 | +// multiple levels of inheritance |
| 71 | +abstract class GrandParent_ { |
| 72 | + public function inherited(): int { |
| 73 | + return 1; |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +abstract class Parent_ extends GrandParent_ { |
| 78 | +} |
| 79 | + |
| 80 | +abstract class Child_ extends Parent_ { |
| 81 | + abstract public function inherited(): int; |
| 82 | +} |
| 83 | + |
| 84 | +// abstract constructor overriding non-abstract constructor |
| 85 | +abstract class ConstructorParent { |
| 86 | + public function __construct() { |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +abstract class ConstructorChild extends ConstructorParent { |
| 91 | + abstract public function __construct(); |
| 92 | +} |
| 93 | + |
| 94 | +// OK: abstract constructor overriding abstract constructor |
| 95 | +abstract class AbstractConstructorParent { |
| 96 | + abstract public function __construct(); |
| 97 | +} |
| 98 | + |
| 99 | +abstract class AbstractConstructorChild extends AbstractConstructorParent { |
| 100 | + abstract public function __construct(); |
| 101 | +} |
0 commit comments