Created
March 31, 2012 05:37
-
-
Save augustohp/2259724 to your computer and use it in GitHub Desktop.
A new way to make singleton in PHP?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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