-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall.php
More file actions
37 lines (36 loc) · 910 Bytes
/
Copy pathall.php
File metadata and controls
37 lines (36 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
interface IPrototype{
public function copy();
}
class Employee implements IPrototype{
private $name;
private $salary;
public function __construct($name,$salary){
$this->name=$name;
$this->salary=$salary;
}
public function getName(){
return $this->name;
}
public function getSalary(){
return $this->salary;
}
public function setSalary($salary){
$this->salary=$salary;
}
public function copy(){
//return clone $this; 浅拷贝
$obj=serialize($this);
return unserialize($obj); //深拷贝
}
public function display(){
echo "$this->name has $this->salary\n";
}
}
$liangbopirates=new Employee('liangbopirates',1000000);
$copy=$liangbopirates->copy();
$liangbopirates->display();
$copy->display();
$liangbopirates->setSalary(800);
$liangbopirates->display();
$copy->display();