File: example.php

Recommend this page to a friend!
  Classes of Aleksandar Zivanovic  >  SingletonTrait  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: SingletonTrait
Trait to implement the singleton design pattern
Author: By
Last change:
Date: 4 years ago
Size: 478 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/trait.Singleton.php';
require_once
__DIR__ . '/class.Example.php';

$cat = Example::getSharedInstance('Cat', 'MEOW');
$brownCat = Example::getSharedInstance('Brown Cat', 'BREOW'); // Brown cat will sound same as $cat as its same instance
$dog = Example::getNewInstance('Dog', 'WOF');

$breakLine = php_sapi_name() === 'cli' ? "\n" : '<br>';

$cat->makeSound($breakLine);
$brownCat->makeSound($breakLine);
$dog->makeSound($breakLine);


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