扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
class ObjectTracker //对象跟踪器 { private static $nextSerial = 0; private $id; private $name; function __construct($name) //构造函数 { $this->name = $name; $this->id = ++self::$nextSerial; } function __clone() //克隆 { $this->name = "Clone of $this->name"; $this->id = ++self::$nextSerial; } function getId() //获取id属性的值 { return($this->id); } function getName() //获取name属性的值 { return($this->name); } } $ot = new ObjectTracker("Zeev's Object"); $ot2 = clone$ot; //输出: 1 Zeev's Object print($ot->getId() . " " . $ot->getName() . ""); //输出: 2 Clone of Zeev's Object print($ot2->getId() . " " . $ot2->getName() . ""); ?> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。