DEV Community

Discussion on: Open Closed Principle

 
leadegroot profile image
Lea de Groot • Edited

Drop the if and generate the class name, quick cut:

If (class_exists($phototype .  ‘Type’)) {
  (new  $phototype)-> open();
} else {
  echo 'Error: '.$phototype.' unsupported';
}
Enter fullscreen mode Exit fullscreen mode

(Untested PHP, but I’m mobile right now)