[doc-en] master: Override: document usage with properties (PHP 8.5) (#4821)

From: Date: Fri, 03 Oct 2025 18:01:10 +0000
Subject: [doc-en] master: Override: document usage with properties (PHP 8.5) (#4821)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-22785@lists.php.net to get a copy of this message
Author: Jiří Pudil (jiripudil) Committer: GitHub (web-flow) Pusher: Crell Date: 2025-10-03T13:01:07-05:00 Commit: https://github.com/php/doc-en/commit/9d3169961438b1cc12d60183fea68dad8516842d Raw diff: https://github.com/php/doc-en/commit/9d3169961438b1cc12d60183fea68dad8516842d.diff Override: document usage with properties (PHP 8.5) (#4821) Changed paths: M language/predefined/attributes/override.xml Diff: diff --git a/language/predefined/attributes/override.xml b/language/predefined/attributes/override.xml index 30c0a5f4400b..4562aee261e2 100644 --- a/language/predefined/attributes/override.xml +++ b/language/predefined/attributes/override.xml @@ -8,12 +8,12 @@ <section xml:id="override.intro"> &reftitle.intro; <simpara> - This attribute is used to indicate that a method is intended - to override a method of a parent class or that it implements - a method defined in an interface. + 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. </simpara> <simpara> - If no method with the same name exists in a parent class or + 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 emitted. </simpara> @@ -41,9 +41,32 @@ </section> + <section role="changelog"> + &reftitle.changelog; + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>&Version;</entry> + <entry>&Description;</entry> + </row> + </thead> + <tbody> + <row> + <entry>8.5.0</entry> + <entry> + <classname>Override</classname> can be applied to properties. + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </section> + <section> &reftitle.examples; - <informalexample> + <example> + <title>Usage with methods</title> <programlisting role="php"> <![CDATA[ <?php @@ -66,7 +89,32 @@ final class Extended extends Base { Fatal error: Extended::boo() has #[\Override] attribute, but no matching parent method exists ]]> </screen> - </informalexample> + </example> + <example> + <title>Usage with properties</title> + <programlisting role="php"> + <![CDATA[ +<?php + +class Base { + protected string $foo; +} + +final class Extended extends Base { + #[\Override] + protected string $boo; +} + +?> +]]> + </programlisting> + &example.outputs.85.similar; + <screen> + <![CDATA[ +Fatal error: Extended::$boo has #[\Override] attribute, but no matching parent property exists +]]> + </screen> + </example> </section> <section xml:id="override.seealso">

« previous php.doc.cvs (#22785) next »