🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »

Prototype in PHP

Prototype is a creational design pattern that allows cloning objects, even complex ones, without coupling to their specific classes.

All prototype classes should have a common interface that makes it possible to copy objects even if their concrete classes are unknown. Prototype objects can produce full copies since objects of the same class can access each other’s private fields.

Learn more about Prototype

Usage of the pattern in PHP



Usage examples: The Prototype pattern is available in PHP out of the box. You can use the clone keyword to create an exact copy of an object. To add cloning support to a class, you need to implement a __clone method.

Prototype in Other Languages

Prototype in Java Prototype in C# Prototype in Python Prototype in Ruby Prototype in Swift Prototype in TypeScript