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
28 changes: 28 additions & 0 deletions language/oop5/anonymous.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ class@anonymous/in/oNi1A0x7f8636ad2021
</screen>
</informalexample>
</note>

<sect2 xml:id="language.oop5.anonymous.readonly">
<title>Readonly anonymous classes</title>
<simpara>
As of PHP 8.3.0, the <literal>readonly</literal> modifier can
be applied to anonymous classes.
</simpara>
<example xml:id="language.oop5.anonymous.readonly.example">
<title>Defining a readonly anonymous class</title>
<programlisting role="php">
<![CDATA[
<?php

// Using an anonymous class
$util->setLogger(new readonly class('[DEBUG]') {
public function __construct(private string $prefix)
{
}

public function log($msg)
{
echo $this->prefix . ' ' . $msg;
}
});
]]>
</programlisting>
</example>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down