Skip to content
Merged
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
51 changes: 44 additions & 7 deletions language/predefined/attributes/allowdynamicproperties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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
Expand All @@ -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>
Expand Down