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
30 changes: 30 additions & 0 deletions language/oop5/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,36 @@ $test->obj = new stdClass;
</programlisting>
</informalexample>
</para>
<para>
As of PHP 8.3.0, readonly properties can be reinitialized when cloning an object
using the <link linkend="object.clone">__clone()</link> method.
<example>
<title>Readonly properties and cloning</title>
<programlisting role="php">
<![CDATA[
<?php
class Test1 {
public readonly ?string $prop;

public function __clone() {
$this->prop = null;
}

public function setProp(string $prop): void {
$this->prop = $prop;
}
}

$test1 = new Test1;
$test1->setProp('foobar');

$test2 = clone $test1;
var_dump($test2->prop); // NULL
?>
]]>
</programlisting>
</example>
</para>
</sect2>

<sect2 xml:id="language.oop5.properties.dynamic-properties">
Expand Down