Skip to content

Commit e150cc6

Browse files
authored
new-features.xml Add an example of cyclic dependencies (#4501)
1 parent 5003a6e commit e150cc6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

appendices/migration74/new-features.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,33 @@ class ChildProducer extends Producer {
7777
Full variance support is only available if autoloading is used. Inside a
7878
single file only non-cyclic type references are possible, because all
7979
classes need to be available before they are referenced.
80+
<informalexample>
81+
<programlisting role="php">
82+
<![CDATA[
83+
<?php
84+
85+
/**
86+
* These classes satisfy the LSP requirements, because C is a subtype of A.
87+
* However, at the time class B is declared, class C is not yet available
88+
*/
89+
class A
90+
{
91+
public function method(): A {}
92+
}
93+
94+
class B extends A
95+
{
96+
// Fatal error: Could not check compatibility between B::method():C and
97+
// A::method(): A, because class С is not available
98+
public function method(): С {}
99+
}
100+
101+
class C extends B {}
102+
103+
?>
104+
]]>
105+
</programlisting>
106+
</informalexample>
80107
</para>
81108
</sect3>
82109

0 commit comments

Comments
 (0)