Skip to content

Commit 7ddc30e

Browse files
[PHP 8.3] Check variance of class constants (#4183)
1 parent cb3794f commit 7ddc30e

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

language/oop5/constants.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,42 @@ Fatal error: Uncaught Error: Cannot access private const Foo::BAZ in …
120120
As of PHP 7.1.0 visibility modifiers are allowed for class constants.
121121
</para>
122122
</note>
123+
<example>
124+
<title>Class constant visibility variance check, as of PHP 8.3.0</title>
125+
<programlisting role="php">
126+
<![CDATA[
127+
<?php
128+
129+
interface MyInterface
130+
{
131+
public const VALUE = 42;
132+
}
133+
134+
class MyClass implements MyInterface
135+
{
136+
protected const VALUE = 42;
137+
}
138+
?>
139+
]]>
140+
</programlisting>
141+
&example.outputs.83;
142+
<screen>
143+
<![CDATA[
144+
Fatal error: Access level to MyClass::VALUE must be public (as in interface MyInterface) …
145+
]]>
146+
</screen>
147+
</example>
148+
<note>
149+
<simpara>
150+
As of PHP 8.3.0 visibility variance is checked more strictly.
151+
Prior to this version, the visibility of a class constant could be different
152+
from the visibility of the constant in the implemented interface.
153+
</simpara>
154+
</note>
123155
<example>
124156
<title>Fetch class constant syntax, as of PHP 8.3.0</title>
125157
<programlisting role="php">
126-
<![CDATA[
158+
<![CDATA[
127159
<?php
128160
class Foo {
129161
public const BAR = 'bar';

0 commit comments

Comments
 (0)