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-- 61Cannot indirectly modify readonly property TestSetOnce::$prop 62Cannot indirectly modify readonly property TestSetOnce::$prop 63Cannot indirectly modify readonly property TestSetTwice::$prop 64Cannot indirectly modify readonly property TestSetTwice::$prop 65