Are you expecting a instance or boolean?
Make a array property in the same class where contains the method controller_instance and store all instances
private $controllers = array(); public function controller_instance($controller_name) { if (isset($this->controllers[$controller_name])) { return $this->controllers[$controller_name]; } return $this->controllers[$controller_name] = new $controller_name(); }
Exemple 2: using ReflectionClass and arguments
private $controllers = array(); public function controller_instance($controller_name, Array $args = array()) { if (isset($this->controllers[$controller_name])) { return $this->controllers[$controller_name]; } $class = new ReflectionClass($controller_name); $instance = $class->newInstanceArgs($args); return $this->controllers[$controller_name] = $instance; }
Router::getRequestedController()return?