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

学习php中clone的使用

2024/4/22 22:21:46发布9次查看
name = $name; $this->age = $age; } function setid( $id ) {
$this->id = $id; } function __clone() { $this->id = 0; }}print ;
$person = new person( bob, 44 );$person->setid( 343 );$person2 = clone $person;print_r( $person );print_r( $person2 );print ;?>
复制代码
演示代码2:
balance = $balance; }}class person {
private $name; private $age; private $id; public $account; function __construct( $name, $age, account $account ) {
$this->name = $name; $this->age = $age; $this->account = $account; } function setid( $id ) {
$this->id = $id; } function __clone() {
$this->id = 0; }}$person = new person( bob, 44, new account( 200 ) );
$person->setid( 343 );$person2 = clone $person;// give $person some money
$person->account->balance += 10;// $person2 sees the credit tooprint $person2->account->balance;// output:
// 210?>
复制代码
官方文档:http://cn2.php.net/__clone
该用户其它信息

VIP推荐

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