PHP Classes

File: msingleton_example.php

Recommend this page to a friend!
  Classes of Artem   MSingleton   msingleton_example.php   Download  
File: msingleton_example.php
Role: Example script
Content type: text/plain
Description: Example
Class: MSingleton
Manage singleton objects
Author: By
Last change: fix
Date: 13 years ago
Size: 655 bytes
 

Contents

Class file image Download
<?php
/**
 * Example
 */

include "MSingleton.php";

/**
 * class Singleton
 *
 * Example child of singleton factory
 *
 * Notice:
 * If call test method twice, Singleton __construct
 * must be called once, and test method twice
 * output must be: * Construct called * * test called * * test called *
 *
 */
class Singleton extends MSingleton {
   
    protected function
__construct() {
    echo
" * Construct called *", PHP_EOL;
    }
   
    protected function
__clone() {}
   
    public function
test() {
    echo
" * test called * ";
    }

}

Singleton::getInstance()->test();
Singleton::getInstance()->test();