MemoryRefresh!

Patterns / Singleton   Singleton



Questions Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


Singleton Pattern provide access to a single resource that is never duplicated.
<?php class Zend_Controller_Front { protected static $_instance = null; public function __construct() { echo "Class load"; } public static function getInstance() { if (null == self::$_instance) { self::$_instance = new self(); // self() points to the class in which it is written } return self::$_instance; } } $fc = Zend_Controller_Front::getInstance(); // Output: Class load $fc = Zend_Controller_Front::getInstance(); // Output: nothing (previews instance used) // --- Look Here --- // $fcn = new Zend_Controller_Front(); // Output: Class load

Related Pages

Observer
Singleton
Front
Factory
Registry
Mvc
Active record


0% 100%
 
 
0 pages 91 pages
1) Singleton Pattern








Singleton Pattern provide access to a single resource that is never duplicated.
<?php class Zend_Controller_Front { protected static $_instance = null; public function __construct() { echo "Class load"; } public static function getInstance() { if (null == self::$_instance) { self::$_instance = new self(); // self() points to the class in which it is written } return self::$_instance; } } $fc = Zend_Controller_Front::getInstance(); // Output: Class load $fc = Zend_Controller_Front::getInstance(); // Output: nothing (previews instance used) // --- Look Here --- // $fcn = new Zend_Controller_Front(); // Output: Class load

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References