From 37df39e10d08fbac225481c0fa0e5a70bee2edf5 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 27 Nov 2024 15:11:21 +0100 Subject: [PATCH 1/2] Add an example for readonly anonymous class --- language/oop5/anonymous.xml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/language/oop5/anonymous.xml b/language/oop5/anonymous.xml index 08b2f7acfad7..e60bfe209c54 100644 --- a/language/oop5/anonymous.xml +++ b/language/oop5/anonymous.xml @@ -173,6 +173,34 @@ class@anonymous/in/oNi1A0x7f8636ad2021 + + + Readonly anonymous classes + + As of PHP 8.3.0, the readonly modifier can + be applied to anonymous classes. + + + Defining a readonly anonymous class + + setLogger(new readonly class('[DEBUG]') { + public function __construct(private string $prefix) + { + } + + public function log($msg) + { + echo $this->prefix . ' ' . $msg; + } +}); +]]> + + +