Last active
December 16, 2015 00:29
-
-
Save manuerumx/5347959 to your computer and use it in GitHub Desktop.
A simple way to store variables in a class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class config{ | |
protected $myconf = array(); | |
abstract function getValue($key, $default=""); | |
abstract function setValue($key, $value); | |
abstract function clearConfig(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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