PHP头条
热点:

php __clone需要注意的问题


 

  __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.phpzy.comtrue/php/7565.htmlTechArticlephp __clone需要注意的问题 __construct( -balance= __construct( , , -name= -age= -account= setId( -id= -id=0 = Person('tom', 33, Account(200 -setId(4 = -account-balance+=500 -account-balance; 当创建一个新副本($p2)时,新对象...

相关文章

相关频道:

PHP之友评论

今天推荐