Skip to content

Instantly share code, notes, and snippets.

@gcoop
Created October 20, 2010 15:47
Show Gist options
  • Save gcoop/636668 to your computer and use it in GitHub Desktop.
Save gcoop/636668 to your computer and use it in GitHub Desktop.
<?php
class This
{
private $data; // Actually protects data enforcing client code to write $obj->getData('foobar');
public function getData($key) // public not needed, but lets be concise and obvious, code for idiots, simple as that because when you look back at your code in 6 months time you are that idiot!
{
if (isset($this->data[$key])) // You will get a notice if you don't check before you do Coding rule #1, check before you presume.
return $this->data[$key];
return null;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment