|
7 | 7 |
|
8 | 8 | <section xml:id="returntypewillchange.intro"> |
9 | 9 | &reftitle.intro; |
| 10 | + <simpara> |
| 11 | + As of PHP 8.1.0, a tentative phase of transitioning to return type declarations |
| 12 | + for internal class methods began. |
| 13 | + </simpara> |
| 14 | + |
10 | 15 | <simpara> |
11 | 16 | Most non-final internal methods now require overriding methods to declare |
12 | | - a compatible return type, otherwise a deprecated notice is emitted during |
13 | | - inheritance validation. This introduces a tentative return type phase: |
14 | | - the engine emits a deprecation notice instead of a fatal error when return |
15 | | - types are incompatible, before they become enforced in a future version. |
| 17 | + a compatible return type. Otherwise, a deprecation notice is emitted during |
| 18 | + inheritance validation warning that the signature violates covariance rules. |
| 19 | + </simpara> |
| 20 | + |
| 21 | + <simpara> |
| 22 | + In a future PHP version, method signature checking will become strict, |
| 23 | + and mismatches will cause a fatal error. |
| 24 | + </simpara> |
| 25 | + |
| 26 | + <simpara> |
16 | 27 | In case the return type cannot be declared for an overriding method due to |
17 | | - PHP cross-version compatibility concerns, |
18 | | - a <code>#[\ReturnTypeWillChange]</code> attribute can be added to silence |
19 | | - the deprecation notice. |
| 28 | + PHP cross-version compatibility concerns, or the overriding method declares |
| 29 | + an incompatible return type, a <code>#[\ReturnTypeWillChange]</code> attribute |
| 30 | + can be added to silence the deprecation notice. |
20 | 31 | </simpara> |
21 | 32 |
|
22 | 33 | <warning> |
23 | 34 | <simpara> |
24 | | - The <classname>ReturnTypeWillChange</classname> attribute suppresses |
25 | | - deprecation warnings during the tentative return type phase <emphasis>only</emphasis>. |
26 | | - It has no effect when overriding methods defined in user-defined classes. |
27 | | - Once internal methods adopt strict types, mismatches in overriding method |
28 | | - signatures will cause a fatal error and this attribute will no longer have any effect. |
| 35 | + When overriding methods defined in user-defined classes, return types are checked |
| 36 | + strictly. A fatal error is emitted on mismatch, even if the overriding method |
| 37 | + is marked with the attribute. |
29 | 38 | </simpara> |
30 | | - </warning> |
31 | 39 |
|
| 40 | + <simpara> |
| 41 | + The <classname>ReturnTypeWillChange</classname> attribute suppresses deprecation |
| 42 | + warnings <emphasis>only</emphasis> during the tentative return type phase. |
| 43 | + After strict type checking is enforced, the attribute will stop working |
| 44 | + and a mismatch in the overriding method signature of an internal class |
| 45 | + will cause a fatal error. |
| 46 | + </simpara> |
| 47 | + </warning> |
32 | 48 | </section> |
33 | 49 |
|
34 | 50 | <section xml:id="returntypewillchange.synopsis"> |
|
0 commit comments