-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Extend #[\Override] to target properties #19061
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
Merged
+449
−19
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d3f5dc
support #[\Override] attribute on properties
jiripudil f6228b5
add closing php tags to tests
jiripudil 3a90c38
fix test code style and wording
jiripudil 2f6eb37
move code into attr_ast conditions
jiripudil a96e15c
simplify property override check
jiripudil 97ed27b
Merge branch 'master' into override-property
TimWolla 52af261
zend_inheritance: Avoid `continue` in multi-purpose loop
TimWolla ecba43a
Merge branch 'master' into override-property
TimWolla bc60d85
zend_inheritance: Clean up scoping in `zend_inheritance_check_overrid…
TimWolla daefe6b
NEWS / UPGRADING
TimWolla 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,39 @@ | ||
--TEST-- | ||
#[\Override]: Properties | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
interface II extends I { | ||
#[\Override] | ||
public mixed $i { get; } | ||
} | ||
|
||
class P { | ||
public mixed $p1; | ||
public mixed $p2; | ||
} | ||
|
||
class PP extends P { | ||
#[\Override] | ||
public mixed $p1; | ||
public mixed $p2; | ||
} | ||
|
||
class C extends PP implements I { | ||
#[\Override] | ||
public mixed $i; | ||
#[\Override] | ||
public mixed $p1; | ||
public mixed $p2; | ||
public mixed $c; | ||
} | ||
|
||
echo "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,16 @@ | ||
--TEST-- | ||
#[\Override]: Properties: No parent class. | ||
--FILE-- | ||
<?php | ||
|
||
class C | ||
{ | ||
#[\Override] | ||
public mixed $c; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::$c has #[\Override] attribute, but no matching parent property exists 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,21 @@ | ||
--TEST-- | ||
#[\Override]: Properties: No parent class, but child implements matching interface. | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
class P { | ||
#[\Override] | ||
public mixed $i; | ||
} | ||
|
||
class C extends P implements I {} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: P::$i has #[\Override] attribute, but no matching parent property exists 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,21 @@ | ||
--TEST-- | ||
#[\Override]: Properties: No parent class, but child implements matching interface (2). | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
class C extends P implements I {} | ||
|
||
class P { | ||
#[\Override] | ||
public mixed $i; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: P::$i has #[\Override] attribute, but no matching parent property exists 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,26 @@ | ||
--TEST-- | ||
#[\Override]: Properties: No parent interface. | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
#[\Override] | ||
public mixed $i { get; } | ||
} | ||
|
||
interface II extends I {} | ||
|
||
|
||
class C implements II { | ||
public mixed $i; | ||
} | ||
|
||
class C2 implements I { | ||
public mixed $i; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: I::$i has #[\Override] attribute, but no matching parent property exists 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,15 @@ | ||
--TEST-- | ||
#[\Override]: Properties: On trait. | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
#[\Override] | ||
public mixed $t; | ||
} | ||
|
||
echo "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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: On used trait without parent method. | ||
TimWolla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
#[\Override] | ||
public mixed $t; | ||
} | ||
|
||
class Foo { | ||
use T; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Foo::$t has #[\Override] attribute, but no matching parent property exists 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-- | ||
#[\Override]: Properties: On used trait with interface method. | ||
TimWolla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
#[\Override] | ||
public mixed $i; | ||
} | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
class Foo implements I { | ||
use T; | ||
} | ||
|
||
echo "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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Parent property is private. | ||
--FILE-- | ||
<?php | ||
|
||
class P { | ||
private mixed $p; | ||
} | ||
|
||
class C extends P { | ||
#[\Override] | ||
public mixed $p; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::$p has #[\Override] attribute, but no matching parent property exists 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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Parent property is private (2). | ||
TimWolla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--FILE-- | ||
<?php | ||
|
||
class P { | ||
private mixed $p; | ||
} | ||
|
||
class C extends P { | ||
#[\Override] | ||
private mixed $p; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::$p has #[\Override] attribute, but no matching parent property exists 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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Parent property is protected. | ||
--FILE-- | ||
<?php | ||
|
||
class P { | ||
protected mixed $p; | ||
} | ||
|
||
class C extends P { | ||
#[\Override] | ||
public mixed $p; | ||
} | ||
|
||
echo "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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Parent property is protected (2). | ||
--FILE-- | ||
<?php | ||
|
||
class P { | ||
protected mixed $p; | ||
} | ||
|
||
class C extends P { | ||
#[\Override] | ||
protected mixed $p; | ||
} | ||
|
||
echo "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,21 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Redeclared trait property. | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
public mixed $t; | ||
} | ||
|
||
class C { | ||
use T; | ||
|
||
#[\Override] | ||
public mixed $t; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::$t has #[\Override] attribute, but no matching parent property exists 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,25 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Redeclared trait property with interface. | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
trait T { | ||
public mixed $i; | ||
} | ||
|
||
class C implements I { | ||
use T; | ||
|
||
#[\Override] | ||
public mixed $i; | ||
} | ||
|
||
echo "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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Valid anonymous class. | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
new class () implements I { | ||
#[\Override] | ||
public mixed $i; | ||
}; | ||
|
||
echo "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,21 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Invalid anonymous class. | ||
--FILE-- | ||
<?php | ||
|
||
interface I { | ||
public mixed $i { get; } | ||
} | ||
|
||
new class () implements I { | ||
public mixed $i; | ||
|
||
#[\Override] | ||
public mixed $c; | ||
}; | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: I@anonymous::$c has #[\Override] attribute, but no matching parent property exists 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,16 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Static property no parent class. | ||
--FILE-- | ||
<?php | ||
|
||
class C | ||
{ | ||
#[\Override] | ||
public static mixed $c; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: C::$c has #[\Override] attribute, but no matching parent property exists 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,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Static property. | ||
--FILE-- | ||
<?php | ||
|
||
class P { | ||
public static mixed $p; | ||
} | ||
|
||
class C extends P { | ||
#[\Override] | ||
public static mixed $p; | ||
} | ||
|
||
echo "Done"; | ||
|
||
?> | ||
--EXPECT-- | ||
Done |
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.
Uh oh!
There was an error while loading. Please reload this page.