Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #27 from noxstyle/master

Proper singleton pattern for Template class
  • Loading branch information...
commit 6bf887c636c7853350999b55151747f3f342a009 2 parents d52a871 + f3f1a78
@phpfreak authored
View
18 environment/classes/template/Template.class.php
@@ -10,6 +10,13 @@
* @http://www.projectpier.org/
*/
class Template {
+
+ /**
+ * Class instance
+ *
+ * @var Object
+ */
+ private static $_instance;
/**
* Array of template variables
@@ -87,12 +94,11 @@ function includeTemplate($template) {
* @param void
* @return Template
*/
- function instance() {
- static $instance;
- if (!instance_of($instance, 'Template')) {
- $instance = new Template();
- } // if
- return $instance;
+ static function instance() {
+ if(!isset(self::$_instance)) {
+ self::$_instance = new self;
+ }
+ return self::$_instance;
} // instance
} // Template
View
14 public/install/library/classes/Template.class.php
@@ -10,6 +10,13 @@
* @http://www.projectpier.org/
*/
class Template {
+
+ /**
+ * Class instance
+ *
+ * @var Object
+ */
+ private static $_instance;
/**
* Array of template variables
@@ -84,11 +91,10 @@ function includeTemplate($template) {
* @return Template
*/
static function instance() {
- static $instance;
- if (!($instance instanceof Template)) {
- $instance = new Template();
+ if(!isset(self::$_instance)) {
+ self::$_instance = new self;
}
- return $instance;
+ return self::$_instance;
} // instance
} // Template
Please sign in to comment.
Something went wrong with that request. Please try again.