Created
April 26, 2017 18:43
-
-
Save afragen/b85f3284508b8c1b0d535bc4c1e45ef2 to your computer and use it in GitHub Desktop.
A Better WordPress Singleton
This file contains 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 | |
//http://jamesdigioia.com/a-better-wordpress-singleton/ | |
class PluginClass | |
{ | |
protected static $instance = null; | |
public function __construct($file) | |
{ | |
if (static::$instance !== null) { | |
throw new Exception; | |
} | |
static::$instance = $this; | |
} | |
public static function get() | |
{ | |
return static::$instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment