1--TEST--
2Readonly property clone indirect variation for JIT
3--FILE--
4<?php
5
6trait CloneSetOnceTrait {
7    public function __clone() {
8        $this->prop[] = 1;
9    }
10}
11
12trait CloneSetTwiceTrait {
13    public function __clone() {
14        $this->prop[] = 1;
15        $this->prop[] = 2;
16    }
17}
18
19class TestSetOnce {
20    use CloneSetOnceTrait;
21    public readonly array $prop;
22    public function __construct() {
23        $this->prop = [];
24    }
25}
26
27class TestSetTwice {
28    use CloneSetTwiceTrait;
29    public readonly array $prop;
30    public function __construct() {
31        $this->prop = [];
32    }
33}
34
35try {
36    var_dump(clone (new TestSetOnce()));
37} catch (Error $e) {
38    echo $e->getMessage(), "\n";
39}
40
41try {
42    var_dump(clone (new TestSetOnce()));
43} catch (Error $e) {
44    echo $e->getMessage(), "\n";
45}
46
47try {
48    var_dump(clone (new TestSetTwice()));
49} catch (Error $e) {
50    echo $e->getMessage(), "\n";
51}
52
53try {
54    var_dump(clone (new TestSetTwice()));
55} catch (Error $e) {
56    echo $e->getMessage(), "\n";
57}
58
59?>
60--EXPECT--
61object(TestSetOnce)#2 (1) {
62  ["prop"]=>
63  array(1) {
64    [0]=>
65    int(1)
66  }
67}
68object(TestSetOnce)#1 (1) {
69  ["prop"]=>
70  array(1) {
71    [0]=>
72    int(1)
73  }
74}
75Cannot modify readonly property TestSetTwice::$prop
76Cannot modify readonly property TestSetTwice::$prop
77