Code example of php prototype mode implementation

黄舟
Release: 2023-03-06 17:44:02
Original
984 people have browsed it

phpPrototype patternCode example of implementation

type = $type; $this->obj = new Obj(); } public function getType() { echoLine($this->type); } public function getObj() { return $this->obj; } } $p = new Prototype('prototype'); $c = clone $p; //浅克隆 var_dump($c === $p); //false var_dump($p->getObj() === $c->getObj()); //true // ================================================== // 深克隆 function deepClone($obj) { if(!is_object($obj)) return null; return unserialize( serialize($obj) ); } $dp = deepClone($p); var_dump($dp === $p); //false var_dump($p->getObj() === $dp->getObj()); //false
Copy after login

The above is the detailed content of Code example of php prototype mode implementation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!