Login   Register  
PHP Classes
elePHPant
Icontem

File: singleton.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrei Alexandru  >  Simple Singleton and Multiton Class  >  singleton.class.php  >  Download  
File: singleton.class.php
Role: Class source
Content type: text/plain
Description: Singleton Implementation Class
Class: Simple Singleton and Multiton Class
Create and manage one or more singleton objects
Author: By
Last change: No cloning
No serialization
Date: 4 years ago
Size: 863 bytes
 

Contents

Class file image Download
<?php
/** 
 * Singleton class
 */

class Singleton
{
    
/**
     * The instance of this class
     * @var object
     */
    
private static $instance null;

    
/**
     * Returns only one instance of this class
     * @return object
     */
    
public static function GetInstance()
    {
        if (!
self::$instance instanceof self)
            
self::$instance = new self();
        return 
self::$instance;
    }

    
/**
     * Private constructor
     */
    
private function  __construct()
    {

    }

    
/**
     * No serialization allowed
     */
    
public function __sleep()
    {
        
trigger_error("No serialization allowed!"E_USER_ERROR);
    }

    
/**
     * No cloning allowed
     */
    
public function __clone()
    {
        
trigger_error("No cloning allowed!"E_USER_ERROR);
    }
}