The question was made because I had an error in finding the actual namespace in the situation:
- parent class namespace \demo\parent\config() (hundreds of lines)
- child class namespace \demo\child1\config() extends \demo\parent\config() (empty)
- child class namespace \demo\child2\config() extends \demo\parent\config() (empty)
But... I uncovered it was not a problem with this but I did a) not fully quantify my class_exists() (assuming the class would take the namespace above it but it does not) AND I had a type in my class_exists line...
Anyway this workaround works for getting the actual namespace:
workaround
If I use something getnamespace:
function getNameSpace()
{
$currentClass = get_class($this);
$refl = new \ReflectionClass($currentClass);
$namespace = $refl->getNamespaceName();
return $namespace . '\\';
}
and then something like the following for instantiating the class in its correct namespace
$module1 = '\\' . self::getNameSpace() . 'Module1';
new $module1
and in the scenario of static classes:
self::callConfig('GetOptionsName');
where "callConfig" =
function callConfig($method,$par='')
{
if ('' == $par)
{
return call_user_func(array(self::getNameSpace() . 'Config',
$method));
}
else
{
return call_user_func_array(array(self::getNameSpace() . 'Config',
$method),$par);
}
}