-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PHP-8.3: Fix #[Override] on traits overriding a parent method without a matching interface (#12205)
- Loading branch information
Showing
7 changed files
with
179 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
#[Override] attribute in trait does not check for parent class implementations | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
public function foo(): void {} | ||
} | ||
|
||
interface I { | ||
public function foo(): void; | ||
} | ||
|
||
trait T { | ||
#[\Override] | ||
public function foo(): void { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
// Works fine | ||
class B implements I { | ||
use T; | ||
} | ||
|
||
// Works fine ("copied and pasted into the target class") | ||
class C extends A { | ||
#[\Override] | ||
public function foo(): void { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
// Does not work | ||
class D extends A { | ||
use T; | ||
} | ||
echo "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,24 @@ | ||
--TEST-- | ||
#[Override] attribute in trait does not check for parent class implementations (Variant with private parent method) | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
private function foo(): void {} | ||
} | ||
|
||
trait T { | ||
#[\Override] | ||
public function foo(): void { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
class D extends A { | ||
use T; | ||
} | ||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: D::foo() has #[\Override] attribute, but no matching parent method exists 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,24 @@ | ||
--TEST-- | ||
#[Override] attribute in trait does not check for parent class implementations (Variant with protected parent method) | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
protected function foo(): void {} | ||
} | ||
|
||
trait T { | ||
#[\Override] | ||
public function foo(): void { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
class D extends A { | ||
use T; | ||
} | ||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
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,24 @@ | ||
--TEST-- | ||
#[Override] attribute in trait does not check for parent class implementations (Variant with __construct) | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
public function __construct() {} | ||
} | ||
|
||
trait T { | ||
#[\Override] | ||
public function __construct() { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
class D extends A { | ||
use T; | ||
} | ||
echo "Done"; | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: D::__construct() has #[\Override] attribute, but no matching parent method exists 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,24 @@ | ||
--TEST-- | ||
#[Override] attribute in trait does not check for parent class implementations (Variant with abstract __construct) | ||
--FILE-- | ||
<?php | ||
|
||
abstract class A { | ||
abstract public function __construct(); | ||
} | ||
|
||
trait T { | ||
#[\Override] | ||
public function __construct() { | ||
echo 'foo'; | ||
} | ||
} | ||
|
||
class D extends A { | ||
use T; | ||
} | ||
echo "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,25 @@ | ||
--TEST-- | ||
#[Override]: Inheritance check of inherited trait method against interface | ||
--FILE-- | ||
<?php | ||
|
||
trait T1 { | ||
public abstract function test(); | ||
} | ||
|
||
trait T2 { | ||
public function test() {} | ||
} | ||
|
||
class A { | ||
use T2; | ||
} | ||
|
||
class B extends A { | ||
use T1; | ||
} | ||
|
||
?> | ||
===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