Skip to content

Instantly share code, notes, and snippets.

@augustohp
Created March 31, 2012 05:37
Show Gist options
  • Save augustohp/2259724 to your computer and use it in GitHub Desktop.
Save augustohp/2259724 to your computer and use it in GitHub Desktop.
A new way to make singleton in PHP?
<?php
/**
* @author: Garith
*/
class Singleton{
protected static $instance = null;
public static function load(){
if(self::$instance === null){
self::$instance = new self();
}
}
// The old fashioned and dumb way of doing (oh my) Singleton in PHP
private function __construct(){
// =D
}
}
Singleton::load();
// $wrong = new Singleton(); //Fatal error too. Oh my. =D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment