-
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
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 |
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 |
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 |
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 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||
--TEST-- | ||||||
#[\Override]: Properties: On used trait without parent method. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--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 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
--TEST-- | ||||||
#[\Override]: Properties: On used trait with interface method. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--FILE-- | ||||||
<?php | ||||||
|
||||||
trait T { | ||||||
#[\Override] | ||||||
public mixed $i; | ||||||
} | ||||||
|
||||||
interface I { | ||||||
public mixed $i { get; } | ||||||
} | ||||||
|
||||||
class Foo implements I { | ||||||
use T; | ||||||
} | ||||||
|
||||||
echo "Done"; | ||||||
|
||||||
?> | ||||||
--EXPECT-- | ||||||
Done |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
#[\Override]: Properties: Parent property is private (2). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the tests where this is a (2) version, I suggest identifying what the difference is, e.g.
|
||
--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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.
to match the other tests