diff --git a/language/predefined/attributes/returntypewillchange.xml b/language/predefined/attributes/returntypewillchange.xml index f5f54acea897..f0891463b0de 100644 --- a/language/predefined/attributes/returntypewillchange.xml +++ b/language/predefined/attributes/returntypewillchange.xml @@ -7,28 +7,45 @@
&reftitle.intro; + + As of PHP 8.1.0, a tentative phase of transitioning to return type declarations + for internal class methods began. + + Most non-final internal methods now require overriding methods to declare - a compatible return type, otherwise a deprecated notice is emitted during - inheritance validation. This introduces a tentative return type phase: - the engine emits a deprecation notice instead of a fatal error when return - types are incompatible, before they become enforced in a future version. + a compatible return type. Otherwise, a deprecation notice is emitted during + inheritance validation, warning that the signature violates covariance rules. + + + + Return type compatibility checks for internal class extensions remain in a soft mode + until a future PHP version enforces strict checking. + At that point, mismatches will cause a fatal error instead of a deprecation notice. + + + In case the return type cannot be declared for an overriding method due to - PHP cross-version compatibility concerns, - a #[\ReturnTypeWillChange] attribute can be added to silence - the deprecation notice. + PHP cross-version compatibility concerns, or the overriding method declares + an incompatible return type, a #[\ReturnTypeWillChange] attribute + can be added to silence the deprecation notice. - The ReturnTypeWillChange attribute suppresses - deprecation warnings during the tentative return type phase only. - It has no effect when overriding methods defined in user-defined classes. - Once internal methods adopt strict types, mismatches in overriding method - signatures will cause a fatal error and this attribute will no longer have any effect. + When overriding methods defined in user-defined classes, return types are checked + strictly. A fatal error is emitted on mismatch, even if the overriding method + is marked with the attribute. - + + The ReturnTypeWillChange attribute suppresses deprecation + warnings only during the tentative return type phase. + After strict type checking is enforced, the attribute will stop working, + and a mismatch in an overriding method signature of an internal class + will cause a fatal error. + +
diff --git a/reference/reflection/reflectionfunctionabstract/gettentativereturntype.xml b/reference/reflection/reflectionfunctionabstract/gettentativereturntype.xml index 850b2ed6477d..68b7a9f58d34 100644 --- a/reference/reflection/reflectionfunctionabstract/gettentativereturntype.xml +++ b/reference/reflection/reflectionfunctionabstract/gettentativereturntype.xml @@ -11,9 +11,9 @@ public ReflectionTypenullReflectionFunctionAbstract::getTentativeReturnType - - Returns the tentative return type associated with the function. - + + Returns the tentative return type associated with the function. + diff --git a/reference/reflection/reflectionfunctionabstract/hastentativereturntype.xml b/reference/reflection/reflectionfunctionabstract/hastentativereturntype.xml index 01cbc5e6fe57..676403af9ce4 100644 --- a/reference/reflection/reflectionfunctionabstract/hastentativereturntype.xml +++ b/reference/reflection/reflectionfunctionabstract/hastentativereturntype.xml @@ -11,9 +11,9 @@ public boolReflectionFunctionAbstract::hasTentativeReturnType - - Returns whether the function has a tentative return type. - + + Returns whether the function has a tentative return type. +