PHP Classes

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    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 31 All time: 11,035 This week: 206Up
Version License PHP version Categories
mezon-singleton 1.0MIT/X Consortium ...5PHP 5, Language, Design Patterns


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: 58 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 185054 in Russian Federation Russian Federation
Week rank: 95 Up9 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 13x




This class implements basic singleton pattern.


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 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  
This week:0
All time:11,035
This week:206Up