clone a class
<?php
class Account {
public $balance;
function __construct( $balance ) {
$this->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("Joe", 35, new Account( 2000 ) );
$person->setId( 111 );
$person2 = clone $person;
$person->account->balance += 110;
print $person2->account->balance;
?>
Related examples in the same category