Sometimes an object needs to modify some of its attributes to become a component of a new object. We create a new object by cloning the prototype.
<?php class Fish{ protected $name; protected $age; protected $weight; protected $message="还是一条活鱼"; function __construct($name, $age, $weight){ $this->name = $name; $this->age = $age; $this->weight = $weight; } function say(){ echo $this->name.';'.$this->age.';'.$this->weight.';'.$this->message; } } class doBraiseFish extends Fish{ function __clone(){ $this->message = '变成红烧鱼'; } } //还是一条活鱼 $fish = new doBraiseFish('草鱼', 2, '2kg'); $Braisefish = clone($fish); $Braisefish->say();
The above has introduced the 15php prototype mode, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.