language/oop5/inheritance.xml
f94d903985119d3ac00f4528551df947f57b667f
...
...
@@ -32,6 +32,9 @@
32
32
<literal>protected</literal> method can be marked as
33
33
<literal>public</literal>, but they cannot be restricted, e.g.
34
34
marking a <literal>public</literal> property as <literal>private</literal>.
35
+
An exception are constructors, whose visibility can be restricted, e.g.
36
+
a <literal>public</literal> constructor can be marked as <literal>private</literal>
37
+
in a child class.
35
38
</para>
36
39

37
40
<note>
...
...
@@ -45,7 +48,7 @@
45
48
<note>
46
49
<para>
47
50
It is not allowed to override a read-write property with a <link linkend="language.oop5.properties.readonly-properties">readonly property</link> or vice versa.
48
-
<example>
51
+
<informalexample>
49
52
<programlisting role="php">
50
53
<![CDATA[
51
54
<?php
...
...
@@ -60,14 +63,13 @@ class B extends A {
60
63
?>
61
64
]]>
62
65
</programlisting>
63
-
</example>
66
+
</informalexample>
64
67
</para>
65
68
</note>
66
69

67
-
<sect2 xml:id="language.oop5.inheritance.examples">
68
-
<example xml:id="language.oop5.inheritance.examples.ex1">
69
-
<title>Inheritance Example</title>
70
-
<programlisting role="php">
70
+
<example>
71
+
<title>Inheritance Example</title>
72
+
<programlisting role="php">
71
73
<![CDATA[
72
74
<?php
73
75

...
...
@@ -101,9 +103,8 @@ $bar->printPHP(); // Output: 'PHP is great'
101
103

102
104
?>
103
105
]]>
104
-
</programlisting>
105
-
</example>
106
-
</sect2>
106
+
</programlisting>
107
+
</example>
107
108

108
109
<sect2 xml:id="language.oop5.inheritance.internal-classes">
109
110
<title>Return Type Compatibility with Internal Classes</title>
...
...
@@ -123,7 +124,7 @@ $bar->printPHP(); // Output: 'PHP is great'
123
124
124
125
<para>
125
126
If the return type cannot be declared for an overriding method due to PHP cross-version compatibility concerns,
126
-
a <code>#[ReturnTypeWillChange]</code> attribute can be added to silence the deprecation notice.
127
+
a <classname>ReturnTypeWillChange</classname> attribute can be added to silence the deprecation notice.
127
128
</para>
128
129
129
130
<example>
...
...
@@ -168,7 +169,7 @@ class MyDateTime extends DateTime
168
169
/**
169
170
* @return DateTime|false
170
171
*/
171
-
#[ReturnTypeWillChange]
172
+
#[\ReturnTypeWillChange]
172
173
public function modify(string $modifier) { return false; }
173
174
}
174
175
175
176