Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check abstract method signatures coming from traits
- Loading branch information
Showing
12 changed files
with
218 additions
and
76 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,18 @@ | ||
--TEST-- | ||
Abstract method from trait enforced in class | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract public function neededByTheTrait(int $a, string $b); | ||
} | ||
|
||
class C { | ||
use T; | ||
|
||
public function neededByTheTrait(array $a, object $b) {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Declaration of C::neededByTheTrait(array $a, object $b) must be compatible with T::neededByTheTrait(int $a, string $b) in %s on line %d |
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,22 @@ | ||
--TEST-- | ||
Mutually incompatible methods from traits are fine as long as the final method is compatible | ||
--FILE-- | ||
<?php | ||
|
||
trait T1 { | ||
abstract public function test(); | ||
} | ||
trait T2 { | ||
abstract public function test(): int; | ||
} | ||
|
||
class C { | ||
use T1, T2; | ||
|
||
public function test(): int {} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
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,18 @@ | ||
--TEST-- | ||
Private abstract method from trait enforced in class | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract private function neededByTheTrait(int $a, string $b); | ||
} | ||
|
||
class C { | ||
use T; | ||
|
||
private function neededByTheTrait(array $a, object $b) {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Declaration of C::neededByTheTrait(array $a, object $b) must be compatible with T::neededByTheTrait(int $a, string $b) in %s on line %d |
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,20 @@ | ||
--TEST-- | ||
Visibility enforcement on abstract trait methods | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract public function method(int $a, string $b); | ||
} | ||
|
||
class C { | ||
use T; | ||
|
||
/* For backwards-compatibility reasons, visibility is not enforced here. */ | ||
private function method(int $a, string $b) {} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
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,18 @@ | ||
--TEST-- | ||
Staticness enforcement on abstract trait methods | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract static public function method(int $a, string $b); | ||
} | ||
|
||
class C { | ||
use T; | ||
|
||
public function method(int $a, string $b) {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot make static method T::method() non static in class C in %s on line %d |
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,20 @@ | ||
--TEST-- | ||
Abstract private trait method not implemented | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract private function method(int $a, string $b); | ||
} | ||
|
||
abstract class C { | ||
use T; | ||
} | ||
|
||
class D extends C { | ||
private function method(int $a, string $b) {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class C must implement 1 abstract private method (C::method) in %s on line %d |
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,23 @@ | ||
--TEST-- | ||
Abstract private trait method forwarded as abstract protected method | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
abstract private function method(int $a, string $b); | ||
} | ||
|
||
abstract class C { | ||
use T; | ||
|
||
abstract protected function method(int $a, string $b); | ||
} | ||
|
||
class D extends C { | ||
protected function method(int $a, string $b) {} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
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
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
Oops, something went wrong.