当前位置:Gxlcms > PHP教程 > php__clone需要注意的问题_PHP教程

php__clone需要注意的问题_PHP教程

时间:2021-07-01 10:21:17 帮助过:3人阅读

  __construct(->balance=     __construct(,,->name=->age=->account= setId(->id=->id=0= Person('tom', 33,  Account(200->setId(4= 
->account->balance+=500
 ->account->balance; 

当创建一个新副本($p2)时,新对象($p2)的中所保存的引用指向的是$p1所引用的同一个$account对象.

如果不想对象属性在被复制之后被共享,可以显式地在__clone方法中复制指向的对象

->id=0->account= ->

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/745143.htmlTechArticle__construct( -balance= __construct( , , -name= -age= -account= setId( -id= -id=0 = Person('tom', 33, Account(200 -setId(4 = -account-balance+=500 -account-balance; 当创建一个新...

人气教程排行