设计模式之原型模式
<?php
/**
* 原型设计模式创建对象的方式是复制克隆初始对象或原型
*
*/
class Employer
{
public $name;
public $career;
public function __construct($name, $carrer)
{
$this->name = $name;
$this->career = $carrer;
}
}
class SepecailEmployer extends Employer
{
public function __clone()
{
$this->career = "civil service";
}
}
$name = "tom"; $carrer = "software enginer";
$employer1 = new SepecailEmployer($name, $carrer);
//tom参加了公务员考试
$offer1 = clone $employer1;
var_dump($employer1, $offer1);