Here is a method, in which a string is passed, using that string an instance is created. Example method:
public function action($actionType)
{
//var_dump(new $actionType);
if (!class_exists($actionType)) {
//throw new Exception
}
if (!(new $actionType) instanceof ActionInterface) {
////throw new Exception
}
$actionType = new $actionType;
echo $actionType->doAction();
}
But I am getting an error of class not found, however when I manually write the class name or manually append the namespace this way $actionType = __namespace__ . "\\$actionType";
, then error goes. Why is that happening?