1--TEST-- 2Readonly property cannot be reset 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 27echo "done"; 28 29?> 30--EXPECT-- 31object(Foo)#2 (1) { 32 ["bar"]=> 33 int(2) 34} 35Cannot modify readonly property Foo::$bar 36done 37