Skip to content

Commit 52e8875

Browse files
authored
Update ReturnTypeWillChange intro for clarity (#5614)
1 parent 1fe6141 commit 52e8875

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

language/predefined/attributes/returntypewillchange.xml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,44 @@
77

88
<section xml:id="returntypewillchange.intro">
99
&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+
1015
<simpara>
1116
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>
1627
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.
2031
</simpara>
2132

2233
<warning>
2334
<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.
2938
</simpara>
30-
</warning>
3139

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>
3248
</section>
3349

3450
<section xml:id="returntypewillchange.synopsis">

reference/reflection/reflectionfunctionabstract/gettentativereturntype.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<modifier>public</modifier> <type class="union"><type>ReflectionType</type><type>null</type></type><methodname>ReflectionFunctionAbstract::getTentativeReturnType</methodname>
1212
<void/>
1313
</methodsynopsis>
14-
<para>
15-
Returns the tentative return type associated with the function.
16-
</para>
14+
<simpara>
15+
Returns the <link linkend="class.returntypewillchange">tentative return type</link> associated with the function.
16+
</simpara>
1717
</refsect1>
1818

1919
<refsect1 role="parameters">

reference/reflection/reflectionfunctionabstract/hastentativereturntype.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<modifier>public</modifier> <type>bool</type><methodname>ReflectionFunctionAbstract::hasTentativeReturnType</methodname>
1212
<void/>
1313
</methodsynopsis>
14-
<para>
15-
Returns whether the function has a tentative return type.
16-
</para>
14+
<simpara>
15+
Returns whether the function has a <link linkend="class.returntypewillchange">tentative return type</link>.
16+
</simpara>
1717

1818
</refsect1>
1919

0 commit comments

Comments
 (0)