Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Preferences {
- private $props = array();
- private static $instance;
- private function __construct() { }
- public static function getInstance() {
- if ( empty( self::$instance ) ) {
- self::$instance = new Preferences();
- }
- return self::$instance;
- }
- public function setProperty( $key, $val ) {
- $this->props[$key] = $val;
- }
- public function getProperty( $key ) {
- return $this->props[$key];
- }
- }
- $pref = Preferences::getInstance();
- $pref->setProperty( "name", "matt" );
- unset( $pref ); // remove the reference
- $pref2 = Preferences::getInstance();
- print $pref2->getProperty( "name" ) ."\n"; // demonstrate value is not lost it will print matt
Add Comment
Please, Sign In to add comment