1--TEST--
2Readonly property cannot be reset after cloning when there is no custom clone handler
3--FILE--
4<?php
5
6class Foo {
7    public function __construct(
8        public readonly int $bar,
9        public readonly int $baz
10    ) {}
11
12    public function wrongCloneOld()
13    {
14        $instance = clone $this;
15        $this->bar++;
16    }
17
18    public function wrongCloneNew()
19    {
20        $instance = clone $this;
21        $instance->baz++;
22    }
23}
24
25$foo = new Foo(1, 1);
26
27try {
28    $foo->wrongCloneOld();
29} catch (Error $exception) {
30    echo $exception->getMessage() . "\n";
31}
32
33try {
34    $foo->wrongCloneNew();
35} catch (Error $exception) {
36    echo $exception->getMessage() . "\n";
37}
38
39?>
40--EXPECT--
41Cannot modify readonly property Foo::$bar
42Cannot modify readonly property Foo::$baz
43