Reputation: 4974
I need to make a dynamic namespace: [module]\controller\[controller]Controller
, but the follow code does not work:
$namespace = '\Account\Controller\LoginController()';
new $namespace;
Like this:
new \Account\Controller\LoginController();
What I forgot?
Upvotes: 2
Views: 147
Reputation: 227220
Don't add the ()
to the string. The ()
are used when calling the function, not in its name.
$namespace = '\Account\Controller\LoginController';
new $namespace;
If you want to pass params, add the ()
to the new
call.
$namespace = '\Account\Controller\LoginController';
new $namespace('abc');
Upvotes: 2