A complete collection of prototype code examples of PHP design patterns (6)



Compared with creating an object (New foo ()) normally, creating a prototype first and then cloning it will save more money.


  • Large amount of data (for example, 1000000 pieces of data are inserted into the database at one time through the ORM model).

UML diagram

Official PHP advanced learning exchange community “click”The management has sorted out some materials, bat and other advanced knowledge systems are ready (relevant learning materials and written questions), and not limited to: distributed architecture, high scalability, high performance, high concurrency, server performance tuning, tp6, laravel, yii2, redis, spool, swoft, Kafka, MySQL optimization, shell script, docker, microservice, nginx and other advanced knowledge points Advanced dry goods


  • BookPrototype.php

    public function setTitle($title)
        $this->title = $title;
  • BarBookPrototype.php
  • FooBookPrototype.php


  • Tests/PrototypeTest.php
setTitle('Foo Book No ' . $i);
            $this->assertInstanceOf(FooBookPrototype::class, $book);

        for ($i = 0; $i < 5; $i++) {
            $book = clone $barPrototype;
            $book->setTitle('Bar Book No ' . $i);
            $this->assertInstanceOf(BarBookPrototype::class, $book);

PHP Internet architect’s growth path * “design patterns” Ultimate Guide

PHP Internet architect 50K growth Guide + general outline of industry problem solving (continuous update)

Interview 10 companies, get 9 offers, PHP interview questions in 2020

If you like my article and want to exchange and study with more senior developers, you can get more technical consultation and guidance related to the interview of large factories. Welcome to join usOur group – click here(group number 856460874).

If the content is good, I hope you can support and encourage me to like it, and welcome to communicate with me. In addition, if you have any questions, please put forward the content you want to see in the comments