我正在尝试克隆一个具有 DateTime 属性的 stdClass 对象。但它失败了。看起来克隆不起作用。我应该编写自己的 __clone() 方法吗?这里有什么问题?
编码:
$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'