Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created October 4, 2009 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codejoust/201455 to your computer and use it in GitHub Desktop.
Save codejoust/201455 to your computer and use it in GitHub Desktop.
PHP5 Config Class.
<?php
class Config{
private static $_data;
private static $_instance;
public function __construct() { }
public static function getInstance(){
if (!self::$_instance){
self::$_instance = new Config();
}
return self::$_instance;
}
public static function __set($name,$value){
self::$_data[$name] = $value;
}
public static function __get($name){
return self::$_data[$name];
}
public static function set($k, $v)
{
return self::$_data[$k] = $v;
}
public static function get($k)
{
return self::$_data[$k];
}
}
/*-- Usage:
$cfg = new Config();
$cfg->test = 'sweet';
$cfg->test; (returns sweet)
If the class can't be accessed as a global:
Config::get('test') (returns sweet)
You also can create more than one instance, however, that data is carried over.
$config = new Config();
$config->test (returns sweet)
--*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment