-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add support for tentative return types of internal methods #6971
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 2 commits
Commits
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
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
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
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
12 changes: 0 additions & 12 deletions
12
Zend/tests/type_declarations/variance/internal_parent.phpt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
Zend/tests/type_declarations/variance/internal_parent/compatible_return_type.phpt
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,17 @@ | ||
--TEST-- | ||
Test that no notice is emitted when the return type/value of the overriding method is compatible with the tentative return type/value of the overridden method | ||
--FILE-- | ||
<?php | ||
class MyDateTimeZone extends DateTimeZone | ||
{ | ||
public static function listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array | ||
{ | ||
return []; | ||
} | ||
} | ||
|
||
var_dump(MyDateTimeZone::listIdentifiers()); | ||
?> | ||
--EXPECT-- | ||
array(0) { | ||
} |
17 changes: 17 additions & 0 deletions
17
Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt
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,17 @@ | ||
--TEST-- | ||
Test that a notice is emitted when the return type/value of the overriding method is incompatible with the tentative return type/value of the overridden method | ||
--FILE-- | ||
<?php | ||
class MyDateTimeZone extends DateTimeZone | ||
{ | ||
public static function listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): string | ||
{ | ||
return ""; | ||
} | ||
} | ||
|
||
var_dump(MyDateTimeZone::listIdentifiers()); | ||
?> | ||
--EXPECTF-- | ||
Deprecated: Declaration of MyDateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): string should be compatible with DateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array in %s on line %d | ||
string(0) "" |
13 changes: 13 additions & 0 deletions
13
Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt
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,13 @@ | ||
--TEST-- | ||
Test that a notice is emitted when the tentative return type of the overridden method is omitted | ||
--FILE-- | ||
<?php | ||
class MyDateTimeZone extends DateTimeZone | ||
{ | ||
public static function listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null) | ||
{ | ||
} | ||
} | ||
?> | ||
--EXPECTF-- | ||
Deprecated: Declaration of MyDateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null) should be compatible with DateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array in %s on line %d |
12 changes: 12 additions & 0 deletions
12
...ests/type_declarations/variance/internal_parent/unresolvable_inheritance_check_param.phpt
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,12 @@ | ||
--TEST-- | ||
Test unresolvable inheritance check due to unavailable parameter type when the parent has a tentative return type. | ||
--FILE-- | ||
<?php | ||
|
||
class Test extends DateTime { | ||
public static function createFromFormat($format, $datetime, Wrong $timezone = null): DateTime|false {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Could not check compatibility between Test::createFromFormat($format, $datetime, ?Wrong $timezone = null): DateTime|false and DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false, because class Wrong is not available in %s on line %d |
12 changes: 12 additions & 0 deletions
12
...sts/type_declarations/variance/internal_parent/unresolvable_inheritance_check_return.phpt
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,12 @@ | ||
--TEST-- | ||
Test unresolvable inheritance check due to unavailable return type when the parent has a tentative return type. | ||
--FILE-- | ||
<?php | ||
|
||
class Test extends DateTime { | ||
public static function createFromFormat($format, $datetime, $timezone = null): Wrong { } | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Could not check compatibility between Test::createFromFormat($format, $datetime, $timezone = null): Wrong and DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false, because class Wrong is not available in %s on line %d |
13 changes: 13 additions & 0 deletions
13
Zend/tests/type_declarations/variance/return_type_will_change_class_error.phpt
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,13 @@ | ||
--TEST-- | ||
Test that the ReturnTypeWillChange attribute cannot target classes | ||
--FILE-- | ||
<?php | ||
|
||
#[ReturnTypeWillChange] | ||
class Foo | ||
{ | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Attribute "ReturnTypeWillChange" cannot target class (allowed targets: method) in %s on line %d |
11 changes: 11 additions & 0 deletions
11
Zend/tests/type_declarations/variance/return_type_will_change_function_error.phpt
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,11 @@ | ||
--TEST-- | ||
Test that the ReturnTypeWillChange attribute cannot target functions | ||
--FILE-- | ||
<?php | ||
|
||
#[ReturnTypeWillChange] | ||
function foo() {} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Attribute "ReturnTypeWillChange" cannot target function (allowed targets: method) in %s on line %d |
14 changes: 14 additions & 0 deletions
14
Zend/tests/type_declarations/variance/return_type_will_change_property_error.phpt
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,14 @@ | ||
--TEST-- | ||
Test that the ReturnTypeWillChange attribute cannot be used with functions | ||
--FILE-- | ||
<?php | ||
|
||
class Foo | ||
{ | ||
#[ReturnTypeWillChange] | ||
public int $bar; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Attribute "ReturnTypeWillChange" cannot target property (allowed targets: method) in %s on line %d |
21 changes: 21 additions & 0 deletions
21
Zend/tests/type_declarations/variance/suppressed_incompatible_return_type.phpt
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-- | ||
Test that the notice can be suppressed when the return type/value of the overriding method is incompatible with the tentative return type/value of the overridden method | ||
--FILE-- | ||
<?php | ||
|
||
class MyDateTime extends DateTime | ||
{ | ||
/** | ||
* @return DateTime|false | ||
*/ | ||
#[ReturnTypeWillChange] | ||
public function modify(string $modifier) { | ||
return false; | ||
} | ||
} | ||
|
||
$date = new MyDateTime("2021-01-01 00:00:00"); | ||
var_dump($date->modify("+1 sec")); | ||
?> | ||
--EXPECT-- | ||
bool(false) |
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.