Mezon PHP Singleton Class: Create object of a class that only has 1 instance

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-11-18 (29 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 22 This week: 2All time: 10,104 This week: 90Up
Version License PHP version Categories
mezon-singleton 1.0MIT/X Consortium ...5PHP 5, Language, Design Patterns
Description Author

This class can be used to create object of a class that only has 1 instance.

Applications need to create a sub-class of this class to make that class only have one instance of the sub-class.

Attempts to create new objects of the same class after when the first instance of that class is created, will return the same object.

The class also provides a function to destroy the only instance of the singleton sub-class.

Picture of Alexey Dodonov
  Performance   Level  
Name: Alexey Dodonov <contact>
Classes: 35 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 4x

 

Details

Singleton

Intro

This class implements basic singleton pattern.

Usage

Using singleton behaviour in your applications is so simple as it can be. Just extend the class Singleton, and enjoy using it!

See the code:

// including all necessary files
require_once( dirname( dirname( dirname( __FILE__ ) ) ).'/conf/conf.php' );
require_once( $MEZON_PATH.'/vendor/singleton/singleton.php' );

// creatingyour own class
class   MyClass extends Singleton
{
    // methods and their implementations
}

That's all!

You can see the Template Engine class for real usage of this pattern.

  Files folder image Files  
File Role Description
Files folder imageTests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Singleton.php Class Class source

  Files folder image Files  /  Tests  
File Role Description
  Plain text file SingletonUnitTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:22
This week:2
All time:10,104
This week:90Up

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