1--TEST--
2Readonly property cannot be op-assigned twice during cloning
3--FILE--
4<?php
5
6class Foo {
7    public function __construct(
8        public readonly int $bar
9    ) {}
10
11    public function __clone()
12    {
13        $this->bar += 2;
14        var_dump($this);
15        $this->bar += 3;
16    }
17}
18
19$foo = new Foo(1);
20
21try {
22    clone $foo;
23} catch (Error $exception) {
24    echo $exception->getMessage() . "\n";
25}
26
27try {
28    clone $foo;
29} catch (Error $exception) {
30    echo $exception->getMessage() . "\n";
31}
32
33?>
34--EXPECT--
35object(Foo)#2 (1) {
36  ["bar"]=>
37  int(3)
38}
39Cannot modify readonly property Foo::$bar
40object(Foo)#2 (1) {
41  ["bar"]=>
42  int(3)
43}
44Cannot modify readonly property Foo::$bar
45