Return to Snippet

Revision: 703
at August 1, 2006 02:00 by px


Updated Code
class SampleClass{
 static private $instance = false;

 function getInstance(){
  if (!self::$instance){
   self::$instance = new SampleClass();
  }
  return self::$instance;
 }
}

//Usage
$SampleClassObject = SampleClass::getInstance();

Revision: 702
at August 1, 2006 01:59 by px


Initial Code
<?php

class SampleClass{
 static private $instance = false;

 function getInstance(){
  if (!self::$instance){
   self::$instance = new SampleClass();
  }
  return self::$instance;
 }
}

//Usage
$SampleClassObject = SampleClass::getInstance();

?>

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

Initial Description

                                

Initial Title
PHP5 Singleton pattern

Initial Tags

                                

Initial Language
PHP