-
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.
fix checking covariant on override static with self & add tests for o…
…verriding static with self in non-final classes
- Loading branch information
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...e_declarations/override_static_type_with_self_in_non_final_class_with_abstract_class.phpt
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-- | ||
Overriding static return types with self in non-final class with abstract class | ||
--FILE-- | ||
<?php | ||
|
||
abstract class B | ||
{ | ||
abstract public function method2(): static; | ||
} | ||
|
||
class Foo extends B | ||
{ | ||
public function method2(): self | ||
{ | ||
return $this; | ||
} | ||
} | ||
|
||
$foo = new Foo(); | ||
|
||
var_dump($foo->method2()); | ||
?> | ||
--EXPECT-- | ||
Fatal error: Declaration of Foo::method2(): Foo must be compatible with B::method2(): static in /app/Zend/tests/type_declarations/override_static_type_with_self_in_non_final_class_with_abstract_class.php on line 10 |
24 changes: 24 additions & 0 deletions
24
...s/type_declarations/override_static_type_with_self_in_non_final_class_with_interface.phpt
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-- | ||
Overriding static return types with self in non-final class with interface | ||
--FILE-- | ||
<?php | ||
|
||
interface A | ||
{ | ||
public function method1(): static; | ||
} | ||
|
||
class Foo implements A | ||
{ | ||
public function method1(): self | ||
{ | ||
return $this; | ||
} | ||
} | ||
|
||
$foo = new Foo(); | ||
|
||
var_dump($foo->method1()); | ||
?> | ||
--EXPECT-- | ||
Fatal error: Declaration of Foo::method1(): Foo must be compatible with A::method1(): static in /app/Zend/tests/type_declarations/override_static_type_with_self_in_non_final_class_with_interface.php on line 10 |
26 changes: 26 additions & 0 deletions
26
...tests/type_declarations/override_static_type_with_self_in_non_final_class_with_trait.phpt
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,26 @@ | ||
--TEST-- | ||
Overriding static return types with self in non-final class with trait | ||
--FILE-- | ||
<?php | ||
|
||
trait C | ||
{ | ||
abstract public function method3(): static; | ||
} | ||
|
||
class Foo | ||
{ | ||
use C; | ||
|
||
public function method3(): self | ||
{ | ||
return $this; | ||
} | ||
} | ||
|
||
$foo = new Foo(); | ||
|
||
var_dump($foo->method3()); | ||
?> | ||
--EXPECT-- | ||
Fatal error: Declaration of Foo::method3(): Foo must be compatible with C::method3(): static in /app/Zend/tests/type_declarations/override_static_type_with_self_in_non_final_class_with_trait.php on line 12 |
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