Home > Backend Development > PHP Tutorial > 15php prototype mode

15php prototype mode

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:05:50
Original
1014 people have browsed it

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();
Copy after login

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.

Related labels:
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 Issues
Why is this ID written like this?
From 1970-01-01 08:00:00
0
0
0
Small question about $this
From 1970-01-01 08:00:00
0
0
0
This file demo.mp4
From 1970-01-01 08:00:00
0
0
0
What's the use of this?
From 1970-01-01 08:00:00
0
0
0
javascript - es6中this
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template