[doc-en] master: Override: document usage with class constants (PHP 8.6) (#6020)
| From: | Alejandro Borrego via GitHub | Date: | Mon, 02 Nov 2026 09:15:07 +0000 |
| Subject: | [doc-en] master: Override: document usage with class constants (PHP 8.6) (#6020) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23904@lists.php.net to get a copy of this message | ||
Author: Alejandro Borrego (abp002)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-02T10:15:03+01:00
Commit: https://github.com/php/doc-en/commit/a65a5e6f1911958433899d22bfe252dedec57b69
Raw diff: https://github.com/php/doc-en/commit/a65a5e6f1911958433899d22bfe252dedec57b69.diff
Override: document usage with class constants (PHP 8.6) (#6020)
Co-authored-by: Alejandro Borrego <210245044+abp002@users.noreply.github.com>
Changed paths:
M language-snippets.ent
M language/predefined/attributes/override.xml
Diff:
diff --git a/language-snippets.ent b/language-snippets.ent
index a721f1edb553..24cc84efe6f7 100644
--- a/language-snippets.ent
+++ b/language-snippets.ent
@@ -481,6 +481,8 @@ is highly discouraged.</simpara></warning>
<!ENTITY example.outputs.85.similar '<simpara xmlns="http://docbook.org/ns/docbook">Output of the
above example in PHP 8.5 is similar to:</simpara>'>
+<!ENTITY example.outputs.86.similar '<simpara xmlns="http://docbook.org/ns/docbook">Output of the
above example in PHP 8.6 is similar to:</simpara>'>
+
<!ENTITY example.outputs.32bit '<simpara xmlns="http://docbook.org/ns/docbook">Output of the
above example on 32 bit machines:</simpara>'>
<!ENTITY example.outputs.64bit '<simpara xmlns="http://docbook.org/ns/docbook">Output of the
above example on 64 bit machines:</simpara>'>
diff --git a/language/predefined/attributes/override.xml
b/language/predefined/attributes/override.xml
index 041dceadfdf3..36676d935a53 100644
--- a/language/predefined/attributes/override.xml
+++ b/language/predefined/attributes/override.xml
@@ -8,13 +8,14 @@
<section xml:id="override.intro">
&reftitle.intro;
<simpara>
- This attribute is used to indicate that a method or a property is intended
- to override a method or a property of a parent class or that it implements
- a method or a property defined in an interface.
+ This attribute is used to indicate that a method, a property, or a class
+ constant (including an enum case) is intended to override a method,
+ a property, or a class constant of a parent class or that it implements
+ a method, a property, or a class constant defined in an interface.
</simpara>
<simpara>
- If no method or property with the same name exists in a parent class or
- in an implemented interface a compile-time error will be
+ If no method, property, or class constant with the same name exists in a
+ parent class or in an implemented interface a compile-time error will be
emitted.
</simpara>
<simpara>
@@ -29,7 +30,7 @@
<classsynopsis class="class">
<ooclass>
- <modifier role="attribute">#[\Attribute(\Attribute::TARGET_METHOD |
\Attribute::TARGET_PROPERTY)]</modifier>
+ <modifier role="attribute">#[\Attribute(\Attribute::TARGET_METHOD |
\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS_CONSTANT)]</modifier>
<modifier>final</modifier>
<classname>Override</classname>
</ooclass>
@@ -51,6 +52,13 @@
</row>
</thead>
<tbody>
+ <row>
+ <entry>8.6.0</entry>
+ <entry>
+ <classname>Override</classname> can be applied to class constants,
+ including enum cases.
+ </entry>
+ </row>
<row>
<entry>8.5.0</entry>
<entry>
@@ -111,6 +119,31 @@ final class Extended extends Base {
<screen>
<![CDATA[
Fatal error: Extended::$boo has #[\Override] attribute, but no matching parent property exists
+]]>
+ </screen>
+ </example>
+ <example>
+ <title>Usage with class constants</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+
+class Base {
+ protected const FOO = 'foo';
+}
+
+final class Extended extends Base {
+ #[\Override]
+ protected const BOO = 'boo';
+}
+
+?>
+]]>
+ </programlisting>
+ &example.outputs.86.similar;
+ <screen>
+<![CDATA[
+Fatal error: Extended::BOO has #[\Override] attribute, but no matching parent constant exists
]]>
</screen>
</example>