1--TEST-- 2Readonly property cannot be reset after cloning when there is a 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 __clone() {} 13 14 public function wrongCloneOld() 15 { 16 $instance = clone $this; 17 $this->bar++; 18 } 19 20 public function wrongCloneNew() 21 { 22 $instance = clone $this; 23 $instance->baz++; 24 } 25} 26 27$foo = new Foo(1, 1); 28 29try { 30 $foo->wrongCloneOld(); 31} catch (Error $exception) { 32 echo $exception->getMessage() . "\n"; 33} 34 35try { 36 $foo->wrongCloneNew(); 37} catch (Error $exception) { 38 echo $exception->getMessage() . "\n"; 39} 40 41?> 42--EXPECT-- 43Cannot modify readonly property Foo::$bar 44Cannot modify readonly property Foo::$baz 45