Skip to content

Commit 3eeeeeb

Browse files
committed
Fully qualify ReturnTypeWillChange in deprecation message
When adding the #[ReturnTypeWillChange] attribute in namespaced code, you also need to use ReturnTypeWillChange, otherwise it will be silently ignored and may result in confusion. Change the deprecation message to suggest #[\ReturnTypeWillChange], which will always work. Closes GH-7454.
1 parent cb5a4ed commit 3eeeeeb

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

Zend/tests/deprecation_to_exception_during_inheritance.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $class = new class extends DateTime {
1717

1818
?>
1919
--EXPECTF--
20-
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
20+
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
2121
Stack trace:
2222
#0 %s(%d): {closure}(8192, 'Return type of ...', '%s', 8)
2323
#1 {main} in %s on line %d

Zend/tests/tentative_type_early_binding.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class Test extends SplObjectStorage {
88
}
99
?>
1010
--EXPECTF--
11-
Deprecated: Return type of Test::valid() should either be compatible with SplObjectStorage::valid(): bool, or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s on line %d
11+
Deprecated: Return type of Test::valid() should either be compatible with SplObjectStorage::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in %s on line %d
1212

1313
Fatal error: Could not check compatibility between Test::current(): Unknown and SplObjectStorage::current(): object, because class Unknown is not available 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: 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
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: 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
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static void ZEND_COLD emit_incompatible_method_error(
997997
if (!return_type_will_change_attribute) {
998998
zend_error_at(E_DEPRECATED, func_filename(child), func_lineno(child),
999999
"Return type of %s should either be compatible with %s, "
1000-
"or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice",
1000+
"or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice",
10011001
ZSTR_VAL(child_prototype), ZSTR_VAL(parent_prototype));
10021002
if (EG(exception)) {
10031003
zend_exception_uncaught_error(

0 commit comments

Comments
 (0)