PHP Classes

File: prototype.php

Recommend this page to a friend!
  Classes of Malik Naik  >  PHP Design Patterns Repository  >  prototype.php  >  Download  
File: prototype.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Design Patterns Repository
Implementation of common design patterns in PHP
Author: By
Last change:
Date: 8 months ago
Size: 1,081 bytes
 

Contents

Class file image Download
<?php

require_once 'vendor/autoload.php';

use
DesignPattern\Prototype\Prototype;
use
DesignPattern\Prototype\BackReference;

// Create an instance of the Prototype object.
$prototype = new Prototype;

// Initialize the values to the Prototype object.
$prototype->intVariable = 512;
$prototype->dateTime = new \DateTime;
$prototype->circularReference = new BackReference($prototype);

// Clone the Prototype object.
$prototype_clone = clone $prototype;


// Check if the objects are cloned successfully.
if ($prototype->intVariable === $prototype_clone->intVariable) {
    print
"Integer value is cloned successfully. \n";
}

if (
$prototype->dateTime !== $prototype_clone->dateTime) {
    print
"DateTime object is cloned successfully. \n";
}

if (
$prototype->circularReference !== $prototype_clone->circularReference) {
    print
"BackReference object with circular reference is cloned successfully. \n";
}

// Outputs:
//
// Integer value is cloned successfully.
// DateTime object is cloned successfully.
// BackReference object with circular reference is cloned successfully.

For more information send a message to info at phpclasses dot org.