-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Check abstract method signatures coming from traits #5068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f880d2
Check abstract method signatures coming from traits
nikic ca149dd
Properly check visibility/staticness and allow abstract private
nikic bec80b3
Don't try to modify the method prototype
nikic ed3b360
Make sure that abstract private is implemented in same class
nikic e81598b
Don't enforce visibility for BC reasons
nikic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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-compatiblity reasons, visibility is not enforced here. */ | ||
private function method(int $a, string $b) {} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.