Last active
December 19, 2015 11:39
-
-
Save ericmann/5949377 to your computer and use it in GitHub Desktop.
Pseudo-singleton for WordPress.
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 | |
class Example { | |
public function __construct() { | |
$this->instantiate(); | |
} | |
public function instantiate() { | |
static $instance = null; | |
if ( null === $instance ) { | |
add_filter( 'example_instance', array( $this, 'instantiate' ) ); | |
$instance = $this; | |
} | |
return $instance; | |
} | |
public function do_something_useful() { | |
} | |
protected function do_something_in_secret() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment