我想克隆一個stdClass對象,它具有一個屬於DateTime的屬性。但它失敗了。它看起來像克隆不起作用。我應該寫我自己的__clone()方法嗎? 這裏有什麼問題?試圖克隆stdClass
的代碼:
$object = new stdClass;
$object->date = new DateTime();
var_dump($object->date);
$cloned = clone($object);
$object->date->modify('+1 day');
var_dump($cloned->date);
輸出:
object DateTime (
->date = string (19) '2013-04-11 11:54:00'
->timezone_type = int 3
->timezone = string (13) 'Europe/Berlin'
object DateTime (
->date = string (19) '2013-04-12 11:54:00'
->timezone_type = int 3
->timezone = string (13) 'Europe/Berlin'
爲什麼不呢?這是第11天和第12天之後的一天 – Voitcus 2013-04-11 10:01:36