Skip to content

Instantly share code, notes, and snippets.

@jtickle
Last active August 29, 2015 13:57
Show Gist options
  • Save jtickle/9420136 to your computer and use it in GitHub Desktop.
Save jtickle/9420136 to your computer and use it in GitHub Desktop.
Better GFMC idea
```
namespace My\Shitty;
use \Exception;
```
# Class: Thing
It is a thing that holds stuff. Takes an array in the constructor in which to put stuff; doesn't care if it's empty or not.
```
class Thing {
protected $stuff;
```
## Constructor
This makes the thing that holds stuff. Takes an array. This whole idea is not working out as well as I thought it would.
```
public function __construct(array &$stuff) {
$this->stuff = $stuff;
}
```
## Method: addStuff($key, $val)
Takes a key and a value and puts them in stuff. Will return the previous value of $key if any, null if not.
```
public function addStuff($key, $val) {
$ret = null;
if(array_key_exists($key, $this->stuff)) {
$ret = $this->stuff[$key];
}
$this->stuff[$key] = $val;
return $ret;
}
```
## Method: getStuff($key)
Get something from stuff.
```
public function getStuff($key) {
if(!array_key_exists($key, $this->stuff)) {
throw new Exception('BAD. BAD DOG. BAD. DOG.');
}
return $this->stuff[$key];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment