Skip to content

Commit 773e9ba

Browse files
authored
Mention ReturnTypeWillChange attribute in the error message (#7183)
1 parent edc87a5 commit 773e9ba

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

Zend/tests/deprecation_to_exception_during_inheritance.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $class = new class extends DateTime {
1313

1414
?>
1515
--EXPECTF--
16-
Fatal error: During inheritance of DateTime: Uncaught Exception: Declaration of DateTime@anonymous::getTimezone() should be compatible with DateTime::getTimezone(): DateTimeZone|false in %s:%d
16+
Fatal error: During inheritance of DateTime: Uncaught Exception: Return type of DateTime@anonymous::getTimezone() should either be compatible with DateTime::getTimezone(): DateTimeZone|false, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s:%d
1717
Stack trace:
18-
#0 %s(%d): {closure}(8192, 'Declaration of ...', '%s', 8)
18+
#0 %s(%d): {closure}(8192, 'Return type of ...', '%s', 8)
1919
#1 {main} in %s on line %d

Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ class MyDateTimeZone extends DateTimeZone
1313
var_dump(MyDateTimeZone::listIdentifiers());
1414
?>
1515
--EXPECTF--
16-
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
16+
Deprecated: Return type of MyDateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): string should either be compatible with DateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s on line %d
1717
string(0) ""

Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class MyDateTimeZone extends DateTimeZone
1010
}
1111
?>
1212
--EXPECTF--
13-
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
13+
Deprecated: Return type of MyDateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null) should either be compatible with DateTimeZone::listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s on line %d

Zend/zend_inheritance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ static void ZEND_COLD emit_incompatible_method_error(
875875

876876
if (!return_type_will_change_attribute) {
877877
zend_error_at(E_DEPRECATED, NULL, func_lineno(child),
878-
"Declaration of %s should be compatible with %s",
878+
"Return type of %s should either be compatible with %s, "
879+
"or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice",
879880
ZSTR_VAL(child_prototype), ZSTR_VAL(parent_prototype));
880881
if (EG(exception)) {
881882
zend_exception_uncaught_error(

0 commit comments

Comments
 (0)