Last active
April 26, 2021 15:56
-
-
Save maheshwaghmare/53f1e1e82a513c07b32b232f3599c26a to your computer and use it in GitHub Desktop.
PHP Class boilerplate - *The Singleton Pattern*
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 | |
/** | |
* MY CLASS NAME | |
* | |
* @package MY PACKAGE | |
* @since 1.0.0 | |
*/ | |
if( ! class_exists( 'MY_CLASS_NAME' ) ) : | |
/** | |
* MY_CLASS_NAME | |
* | |
* @since 1.0.0 | |
*/ | |
class MY_CLASS_NAME { | |
/** | |
* Instance | |
* | |
* @access private | |
* @since 1.0.0 | |
*/ | |
private static $instance; | |
/** | |
* Initiator | |
* | |
* @since 1.0.0 | |
* @return object initialized object of class. | |
*/ | |
public static function instance(){ | |
if ( ! isset( self::$instance ) ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
/** | |
* Constructor | |
* | |
* @since 1.0.0 | |
*/ | |
public function __construct() { | |
} | |
} | |
/** | |
* Kicking this off by calling 'instance()' method | |
*/ | |
MY_CLASS_NAME::instance(); | |
// OR | |
// $my_class_name = MY_CLASS_NAME::instance(); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment