Last active
May 18, 2016 23:46
-
-
Save Zetzumarshen/f920c1034293b1abc4f42bc886395874 to your computer and use it in GitHub Desktop.
PHP Gotcha: Factory Pattern
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
class carFactory | |
{ | |
public function createObject($carClass) | |
{ | |
$file = $carClass . '.php'; | |
require_once $file; | |
$obj = new $carClass; // magic | |
return $obj | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment