Skip to content

Instantly share code, notes, and snippets.

@manuerumx
Last active December 16, 2015 00:29
Show Gist options
  • Save manuerumx/5347959 to your computer and use it in GitHub Desktop.
Save manuerumx/5347959 to your computer and use it in GitHub Desktop.
A simple way to store variables in a class
abstract class config{
protected $myconf = array();
abstract function getValue($key, $default="");
abstract function setValue($key, $value);
abstract function clearConfig();
}
require_once 'config.php'
class myClass extends config{
public function getValue($key, $default = "") {
if(isset($this->myconf[$key]) && !empty($this->myconf[$key])){
return $this->myconf[$key];
}else{
return $default;
}
}
public function setValue($key, $value) {
$this->myconf[$key] = $value;
}
/**
* Clear the stored data
*/
public function clearConfig() {
$this->myconf = NULL;
}
/*
More methods
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment