1--TEST-- 2Test that __clone() unset and reassign properties 3--FILE-- 4<?php 5 6class Foo { 7 public function __construct( 8 public readonly stdClass $bar, 9 ) {} 10 11 public function __clone() 12 { 13 unset($this->bar); 14 var_dump($this); 15 $this->bar = new stdClass(); 16 } 17} 18 19$foo = new Foo(new stdClass()); 20var_dump($foo); 21$foo2 = clone $foo; 22 23var_dump($foo); 24var_dump($foo2); 25 26?> 27--EXPECTF-- 28object(Foo)#1 (%d) { 29 ["bar"]=> 30 object(stdClass)#2 (%d) { 31 } 32} 33object(Foo)#3 (%d) { 34 ["bar"]=> 35 uninitialized(stdClass) 36} 37object(Foo)#1 (%d) { 38 ["bar"]=> 39 object(stdClass)#2 (%d) { 40 } 41} 42object(Foo)#3 (%d) { 43 ["bar"]=> 44 object(stdClass)#4 (%d) { 45 } 46} 47