Singleton()
Description #
A class to be used as a base for all singleton classes.
Source #
File: includes/class/class-singleton.php
abstract class Singleton {
/**
* Cloning is forbidden.
*
* @return void
* @since 4.1.8
*/
private function __clone() {
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'anspress-question-answer' ), '1.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 4.1.8
* @since 4.2.0 Fixed: warning `__wakeup must be public`.
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'anspress-question-answer' ), '1.0.0' );
}
/**
* Creates or returns an instance of this class.
*
* @return AnsPress\Singleton A single instance of this class.
* @since 4.1.8
*/
public static function init() {
if ( is_null( static::$instance ) ) {
static::$instance = new static();
static::$instance->run_once();
}
return static::$instance;
}
/**
* Placeholder function which is called only once.
*
* @return void
* @since 4.1.8
*/
public function run_once() {
}
}
Expand full source code Collapse full source code View on GitHub: includes/class/class-singleton.php:25
Add your comment