多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ <?php interface Prototype{public function copy();} class ConcreatePrototype implements Prototype{ private $_obj; public function __construct($obj){ $this->_obj = $obj; } public function copy(){return clone $this;} } class Demo{} $demo = new Demo(); $obj1 = new ConcreatePrototype($demo); $obj2 = $obj1->copy(); var_dump($obj1,$obj2); ~~~ 构造多个相同的对象 [root@centos6 dp]# php prototype.php object(ConcreatePrototype)#2 (1) { ["_obj":"ConcreatePrototype":private]=> object(Demo)#1 (0) { } } object(ConcreatePrototype)#3 (1) { ["_obj":"ConcreatePrototype":private]=> object(Demo)#1 (0) { } }