We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

px on 08/01/06


Tagged

pattern php5 Singleton


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

px
vaaaska


PHP5 Singleton pattern


Published in: PHP 


URL: http://simplex.pp.ru/tech/php/singleton

  1. class SampleClass{
  2. static private $instance = false;
  3.  
  4. function getInstance(){
  5. if (!self::$instance){
  6. self::$instance = new SampleClass();
  7. }
  8. return self::$instance;
  9. }
  10. }
  11.  
  12. //Usage
  13. $SampleClassObject = SampleClass::getInstance();

Report this snippet 

You need to login to post a comment.