1--TEST--
2Readonly property can be reset once during cloning even after a type error
3--FILE--
4<?php
5
6class Foo {
7    public function __construct(
8        public readonly int $bar
9    ) {}
10
11    public function __clone()
12    {
13        try {
14            $this->bar = "foo";
15        } catch (Error $e) {
16            echo $e->getMessage() . "\n";
17        }
18
19        $this->bar = 2;
20    }
21}
22
23$foo = new Foo(1);
24
25var_dump(clone $foo);
26var_dump(clone $foo);
27
28?>
29--EXPECTF--
30Cannot assign string to property Foo::$bar of type int
31object(Foo)#%d (%d) {
32  ["bar"]=>
33  int(2)
34}
35Cannot assign string to property Foo::$bar of type int
36object(Foo)#%d (%d) {
37  ["bar"]=>
38  int(2)
39}
40