我想使用__clone()来创建类对象的副本,之后我想打印该副本对象。 这里是代码:__clone方法不复制类对象
<?php
class Test {
public static $counter = 0;
public $id;
public $other;
public function __construct(){
$this->id = self::$counter++;
}
public function __clone()
{
$this->other = $that->other;
$this->id = self::$counter++;
}
}
$obj = new Test();
$copy = clone $obj;
print_r($copy);
?>
有什么问题? –
'$ that'应该是什么? – Vatev