Skip to content

Document dynamic properties #1942

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

Merged
merged 2 commits into from
Nov 7, 2022
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
22 changes: 22 additions & 0 deletions language/oop5/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ $test->obj = new stdClass;
</para>
</sect2>

<sect2 xml:id="language.oop5.properties.dynamic-properties">
<title>Dynamic properties</title>
<para>
If trying to assign to a non existant property on an &object;,
PHP will automatically create a corresponding property.
This dynamically created property will <emphasis>only</emphasis> be
available on this class instance.
</para>

<warning>
<simpara>
Dynamic properties are deprecated as of PHP 8.2.0.
It is recommended to declare the property instead.
To handle arbitrary property names, the class should implement the magic
methods <link linkend="object.get">__get()</link> and
<link linkend="object.set">__set()</link>.
At last resort the class can be marked with the
<code>#[\AllowDynamicProperties]</code> attribute.
</simpara>
</warning>
</sect2>

</sect1>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down