PHP5 Singleton pattern


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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();

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.