Created
April 6, 2016 15:05
-
-
Save bramus/5fafea6bbe16415a9cef11ff51530900 to your computer and use it in GitHub Desktop.
Simple PHP Key-Value DataStore
This file contains hidden or 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
<?php | |
namespace Bramus; | |
/** | |
* Simple Key-Value DataStore to keep variables on | |
*/ | |
class Datastore { | |
private $data = array(); | |
public function __get($name) { | |
return isset($this->data[$name]) ? $this->data[$name] : null; | |
} | |
public function __set($name, $value) { | |
$this->data[$name] = $value; | |
} | |
public function __call($name, $args) { | |
return isset($this->data[$name]) ? $this->data[$name] : (isset($args[0]) ? $args[0] : null); | |
} | |
} | |
// EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage