Created
January 9, 2017 04:10
-
-
Save camilopayan/a4b5bf80cc728a91e56511505a3192f6 to your computer and use it in GitHub Desktop.
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 | |
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