1--TEST--
2__clone() cannot indirectly modify unlocked readonly properties
3--FILE--
4<?php
5
6class Foo {
7    public function __construct(
8        public readonly array $bar
9    ) {}
10
11    public function __clone()
12    {
13        $this->bar['bar'] = 'bar';
14    }
15}
16
17$foo = new Foo([]);
18// First call fills the cache slot
19try {
20    var_dump(clone $foo);
21} catch (Error $e) {
22    echo $e->getMessage(), "\n";
23}
24try {
25    var_dump(clone $foo);
26} catch (Error $e) {
27    echo $e->getMessage(), "\n";
28}
29
30?>
31--EXPECT--
32Cannot indirectly modify readonly property Foo::$bar
33Cannot indirectly modify readonly property Foo::$bar
34