我想使用__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