From 3eeeeeb1049d95e8d088afbe59e2733817c03f92 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 2 Sep 2021 18:38:52 +0200 Subject: [PATCH] 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. --- Zend/tests/deprecation_to_exception_during_inheritance.phpt | 2 +- Zend/tests/tentative_type_early_binding.phpt | 2 +- .../variance/internal_parent/incompatible_return_type.phpt | 2 +- .../variance/internal_parent/missing_return_type.phpt | 2 +- Zend/zend_inheritance.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Zend/tests/deprecation_to_exception_during_inheritance.phpt b/Zend/tests/deprecation_to_exception_during_inheritance.phpt index 548b8e076aa..dd0adec36a5 100644 --- a/Zend/tests/deprecation_to_exception_during_inheritance.phpt +++ b/Zend/tests/deprecation_to_exception_during_inheritance.phpt @@ -17,7 +17,7 @@ $class = new class extends DateTime { ?> --EXPECTF-- -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 +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 Stack trace: #0 %s(%d): {closure}(8192, 'Return type of ...', '%s', 8) #1 {main} in %s on line %d diff --git a/Zend/tests/tentative_type_early_binding.phpt b/Zend/tests/tentative_type_early_binding.phpt index cc26e7d93b7..926ace5772b 100644 --- a/Zend/tests/tentative_type_early_binding.phpt +++ b/Zend/tests/tentative_type_early_binding.phpt @@ -8,6 +8,6 @@ class Test extends SplObjectStorage { } ?> --EXPECTF-- -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 +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 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 diff --git a/Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt b/Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt index e69e0a6b945..f6782db9a01 100644 --- a/Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt +++ b/Zend/tests/type_declarations/variance/internal_parent/incompatible_return_type.phpt @@ -13,5 +13,5 @@ class MyDateTimeZone extends DateTimeZone var_dump(MyDateTimeZone::listIdentifiers()); ?> --EXPECTF-- -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 +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 string(0) "" diff --git a/Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt b/Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt index 21e6ba6d140..e1166672498 100644 --- a/Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt +++ b/Zend/tests/type_declarations/variance/internal_parent/missing_return_type.phpt @@ -10,4 +10,4 @@ class MyDateTimeZone extends DateTimeZone } ?> --EXPECTF-- -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 +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 diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index a6512657223..175c8220ad5 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -997,7 +997,7 @@ static void ZEND_COLD emit_incompatible_method_error( if (!return_type_will_change_attribute) { zend_error_at(E_DEPRECATED, func_filename(child), func_lineno(child), "Return type of %s should either be compatible with %s, " - "or the #[ReturnTypeWillChange] attribute should be used to temporarily suppress the notice", + "or the #[\\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice", ZSTR_VAL(child_prototype), ZSTR_VAL(parent_prototype)); if (EG(exception)) { zend_exception_uncaught_error(