Skip to content

Instantly share code, notes, and snippets.

@camilopayan
Created January 9, 2017 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camilopayan/a4b5bf80cc728a91e56511505a3192f6 to your computer and use it in GitHub Desktop.
Save camilopayan/a4b5bf80cc728a91e56511505a3192f6 to your computer and use it in GitHub Desktop.
<?php
class AnimalParade
{
private function getMonkey()
{
try {
return $dataSource->wrangleAMonkey();
} catch (NotFoundException $e) {
// The null object pattern, quick and dirty-like
return new class() extends Animal {
public function soundOff()
{
echo "Pretend to be a monkey.";
}
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment