clone
使用环境:
对象在对象之间没办法实现值传递.
当需要一个对象,与之前对象有很多共同之处 需要clone出来一个 只是在内部属性稍作调整.
1 class Person{ 2 public $name; 3 public $age; 4 5 //__clone() 当程序有clone时候 执行此方法 自动执行。 6 public function __clone(){ 7 //调整必要的属性区别 8 $this->name = 'jany'; 9 } 10 11 } 12 13 $student = new Person(); 14 15 //当克隆对象发生时,内部程序会自动调用 __clone()魔术方法 16 $teacher = clone $student; 17 18 --------------------------------------------------------------------------- 19 克隆分为:深克隆 和 浅克隆