Topic by Bishnu Paudel
Hi all,
I am trying to use dynamic class name(custom object name) and invoke the fetch method of it. But I am getting error saying that the class does not exits.
Here is my currently working code:
switch($groupNumber)
{
case 101:
$group= RNCPHP\Integration\Cal_101_C::fetch($groupId);
break;
case 102:
$group= RNCPHP\Integration\Cal_102_C::fetch($groupId);
break;
case 103:
$group= RNCPHP\Integration\Cal_103_C::fetch($groupId);
break;
case 201:
$group= RNCPHP\Integration\Cal_201_C::fetch($groupId);
break;
case 202:
$group= RNCPHP\Integration\Cal_202_C::fetch($groupId);
break;
case 203:
$group= RNCPHP\Integration\Cal_203_C::fetch($groupId);
break;
}
What I am trying to do:
$className="RNCPHP\Integration\Cal_". $groupNumber."_C";
$r = new ReflectionClass($className);
$object=$r->getMethod('fetch')->invoke($groupId);
What I am getting:
Class RNCPHP\Integration\Cal_101_C does not exists
Any ideas how to make it work using reflection?
Thanks,