-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from DaveLiddament/feature/override
ADD Override attribute
- Loading branch information
Showing
5 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OverrideOnClass { | ||
|
||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
abstract class BaseClass { | ||
|
||
abstract public function method1(): void; | ||
|
||
public function method2(): void {} | ||
|
||
public function anotherMethod(): void {} | ||
|
||
} | ||
|
||
|
||
class Class1 extends BaseClass { | ||
|
||
#[Override] public function method1(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method2(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method4(): void // ERROR | ||
{ | ||
} | ||
} | ||
|
||
|
||
new class extends BaseClass { | ||
#[Override] public function method1(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method2(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method3(): void // ERROR | ||
{ | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OverrideOnInterface { | ||
|
||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
abstract class AnInterface { | ||
|
||
abstract public function method1(): void; | ||
|
||
public function method2(): void {} | ||
|
||
public function anotherMethod(): void {} | ||
|
||
} | ||
|
||
|
||
class Class1 extends AnInterface { | ||
|
||
#[Override] public function method1(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method2(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method4(): void // ERROR method4 | ||
{ | ||
} | ||
} | ||
|
||
|
||
new class extends AnInterface { | ||
#[Override] public function method1(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method2(): void | ||
{ | ||
} | ||
|
||
#[Override] public function method3(): void // ERROR method3 | ||
{ | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace overrideRfcExample1 { | ||
|
||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
class P { | ||
protected function p(): void {} | ||
} | ||
|
||
class C extends P { | ||
#[Override] | ||
public function p(): void {} | ||
} | ||
} | ||
|
||
namespace overrideRfcExample2 { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
class Foo implements \IteratorAggregate | ||
{ | ||
#[Override] | ||
public function getIterator(): \Traversable | ||
{ | ||
yield from []; | ||
} | ||
} | ||
} | ||
|
||
|
||
namespace overrideRfcExample5 { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
interface I { | ||
public function i(); | ||
} | ||
|
||
interface II extends I { | ||
#[Override] | ||
public function i(); | ||
} | ||
|
||
class P { | ||
public function p1() {} | ||
public function p2() {} | ||
public function p3() {} | ||
public function p4() {} | ||
} | ||
|
||
class PP extends P { | ||
#[Override] | ||
public function p1() {} | ||
public function p2() {} | ||
#[Override] | ||
public function p3() {} | ||
} | ||
|
||
class C extends PP implements I { | ||
#[Override] | ||
public function i() {} | ||
#[Override] | ||
public function p1() {} | ||
#[Override] | ||
public function p2() {} | ||
public function p3() {} | ||
#[Override] | ||
public function p4() {} | ||
public function c() {} | ||
} | ||
} | ||
|
||
namespace overrideRfcExample6 { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
class C | ||
{ | ||
#[Override] public function c(): void {} // ERROR c | ||
} | ||
} | ||
|
||
namespace overrideRfcExample7 { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
interface I { | ||
public function i(): void; | ||
} | ||
|
||
class P { | ||
#[Override] public function i(): void {} // ERROR i | ||
} | ||
|
||
class C extends P implements I {} | ||
} | ||
|
||
|
||
|
||
namespace overrideRfcExample9 { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\Override; | ||
|
||
class P { | ||
private function p(): void {} | ||
} | ||
|
||
class C extends P { | ||
#[Override] public function p(): void {} // ERROR p | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DaveLiddament\PhpLanguageExtensions; | ||
|
||
/** | ||
* Add to a method to indicate it is overriding a method in a parent class/interface. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_METHOD)] | ||
final class Override | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |