1--TEST-- 2Readonly property can be reset once 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++; 14 } 15} 16 17$foo = new Foo(1); 18 19var_dump(clone $foo); 20 21$foo2 = clone $foo; 22var_dump($foo2); 23 24var_dump(clone $foo2); 25 26?> 27--EXPECTF-- 28object(Foo)#%d (%d) { 29 ["bar"]=> 30 int(2) 31} 32object(Foo)#%d (%d) { 33 ["bar"]=> 34 int(2) 35} 36object(Foo)#%d (%d) { 37 ["bar"]=> 38 int(3) 39} 40