Advertisement
NilsCorver

PHP Singleton

Nov 9th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. <?php
  2.  
  3. class Settings {
  4.     static public function instance () {
  5.         static $resource = null;
  6.         if(is_null($resource))
  7.             $resource = new Settings();
  8.         return $resource;
  9.     }
  10.    
  11.     public $location = 'http://unknown/';
  12.    
  13.     final private function __construct () {}
  14. }
  15.  
  16. // one file
  17. $settings = Settings::instance();
  18. $settings->location = 'http://www.e-mark.nl/';
  19.  
  20. // other file
  21. $settings = Settings::instance();
  22. echo $settings->location; // 'http://www.e-mark.nl/'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement