Let's say for an instance I have a class:
class User {
}
And I have a variable:
$model = 'User';
How to create an instance new Userwhen I am currently in the namespace?
new $modelworks when I'm not in the namespace. But what if I'm in a namespace and Usernot in a namespace.
Something like this does not work:
namespace Admin;
class Foo {
function fighter($model)
{
return new \$model;
}
}
}
source
share