Skip to content

Override: document usage with properties (PHP 8.5) #4821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions language/predefined/attributes/override.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand All @@ -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">
Expand Down
Loading