I am stuck with a namespace conflict. My class file looks like this (in short). I have written comment stuck here
where i am having the problem.
<?php
//file location - /core/controller/EH_Loader.php
namespace core\controller;
class EH_Loader {
//some public functions here...
private function _create_instance($type, $class, $params, $method_name, $data) {
//create a reflection class so that we can pass parameters to the constructor
// class_alias('Application\Controller\\'.$class, $class, FALSE);
$ref_class = new \ReflectionClass(new $class()); //stuck here - more explainiantion below
if (is_array($params) && sizeof($params) > 0) {
$instance = $ref_class->newInstanceArgs($params);
} else {
$instance = new $class();
}
$this->logger->info("$type object created for $class class");
//call the method along with parameters, if they exist !
if (method_exists($instance, $method_name)) {
call_user_func_array(array($instance, $method_name), $data);
}
return $instance;
}
}
new $class
is in a different namcespace and it lies inside /application/controller/test.php
. I am not able to load that file through psr-4. How can i achieve this. Also how can I make my $class
file in global namespace.
EDIT: The problem is a bit more serious. The new $class
looks like this. It extends another class which has the same namespace namespace core\controller;
//namespace application\controller;
class test extends EH_Base {
function __construct() {
parent::__construct();
}
}