Last active
August 29, 2015 13:57
-
-
Save jtickle/9420136 to your computer and use it in GitHub Desktop.
Better GFMC idea
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
``` | |
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