您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php实现对象克隆的方法,php对象克隆_PHP教程

2025/7/3 5:55:25发布21次查看
php实现对象克隆的方法,php对象克隆本文实例讲述了php实现对象克隆的方法。分享给大家供大家参考。具体如下:
id = $id; } function getid() { return $this->id; } function setname($name) { $this->name = $name; } function getname() { return $this->name; } } //创建一个新的staff对象并初始化 $ee1 = new staff(); $ee1->setid(145); $ee1->setname(simon); //克隆一个新的对象 $ee2 = clone $ee1; //重新设置新对象的id值 $ee2->setid(146); //输出ee1和ee2 echo ee1 id: .$ee1->getid().
; echo ee1 name: .$ee1->getname().
; echo ee2 id: .$ee2->getid().
; echo ee2 name: .$ee2->getname().
; ?>
id = $id; } function getid() { return $this->id; } function setname($name) { $this->name = $name; } function getname() { return $this->name; } //这里是__clone函数 function __clone() { $this->id = $this->id + 1; } } //创建一个新的staff对象并初始化 $ee1 = new staff(); $ee1->setid(145); $ee1->setname(simon); //克隆一个新的对象 $ee2 = clone $ee1; //重新设置新对象的id值 //$ee2->setid(146); //输出ee1和ee2 echo ee1 id: .$ee1->getid().
; echo ee1 name: .$ee1->getname().
; echo ee2 id: .$ee2->getid().
; echo ee2 name: .$ee2->getname().
; ?>
希望本文所述对大家的php程序设计有所帮助。
http://www.bkjia.com/phpjc/1019432.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1019432.htmltecharticlephp实现对象克隆的方法,php对象克隆 本文实例讲述了php实现对象克隆的方法。分享给大家供大家参考。具体如下: php //定义类staff,其中包...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product