[DOC-CVS] [doc-en] master: Add inherited class example to AllowDynamicProperties (#5458)

[email protected] (Jordi Kroon via GitHub) Fri, 3 Apr 2026 19:24:43 +0000
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Jordi Kroon (jordikroon)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2026-04-03T21:24:24+02:00

Commit: https://github.com/php/doc-en/commit/be3574f52a050f3dd9aa6ca9dffc19b0484c250a
Raw diff: https://github.com/php/doc-en/commit/be3574f52a050f3dd9aa6ca9dffc19b0484c250a.diff

Add inherited class example to AllowDynamicProperties (#5458)

Changed paths:
  M  language/predefined/attributes/allowdynamicproperties.xml


Diff:

diff --git a/language/predefined/attributes/allowdynamicproperties.xml b/language/predefined/attributes/allowdynamicproperties.xml
index f5cf21bcb63a..bd9a7d16898e 100644
--- a/language/predefined/attributes/allowdynamicproperties.xml
+++ b/language/predefined/attributes/allowdynamicproperties.xml
@@ -7,10 +7,19 @@
 
   <section xml:id="allowdynamicproperties.intro">
    &reftitle.intro;
-   <para>
+   <simpara>
     This attribute is used to mark classes that allow
     <link linkend="language.oop5.properties.dynamic-properties">dynamic properties</link>.
-   </para>
+   </simpara>
+   <note>
+    <simpara>
+     Although attributes themselves are not inherited, the effect of the
+     <literal>AllowDynamicProperties</literal> attribute <emphasis>is</emphasis>
+     inherited. Child classes of a class marked with this attribute will also
+     allow dynamic properties, even if they do not explicitly declare the
+     attribute.
+    </simpara>
+   </note>
   </section>
 
   <section xml:id="allowdynamicproperties.synopsis">
@@ -33,12 +42,13 @@
 
   <section>
    &reftitle.examples;
-   <para>
+   <simpara>
     Dynamic properties are deprecated as of PHP 8.2.0,
     thus using them without marking the class with this attribute will emit
     a deprecation notice.
-   </para>
-   <informalexample>
+   </simpara>
+   <example>
+    <title>AllowDynamicProperties with non-existing property</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -61,12 +71,39 @@ $o2->nonExistingProp = true;
 Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10
 ]]>
     </screen>
-   </informalexample>
+   </example>
+   <example>
+    <title>AllowDynamicProperties with non-existing property in inherited class</title>
+    <programlisting role="php">
+     <![CDATA[
+<?php
+class DefaultBehaviour { }
+
+#[\AllowDynamicProperties]
+class ClassAllowsDynamicProperties { }
+
+class InheritedClassAllowsDynamicProperties extends ClassAllowsDynamicProperties { }
+
+$o1 = new DefaultBehaviour();
+$o2 = new InheritedClassAllowsDynamicProperties();
+
+$o1->nonExistingProp = true;
+$o2->nonExistingProp = true;
+?>
+]]>
+    </programlisting>
+    &example.outputs.82;
+    <screen>
+     <![CDATA[
+Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 12
+]]>
+    </screen>
+   </example>
   </section>
 
   <section xml:id="allowdynamicproperties.seealso">
    &reftitle.seealso;
-   <para><link linkend="language.attributes">Attributes overview</link></para>
+   <simpara><link linkend="language.attributes">Attributes overview</link></simpara>
   </section>
 
  </partintro>