The code:
$className = '\MyNamespace\MyClass';
$object = new $className();
throws error ‘Class not found’
But this code:
$object = new \MyNamespace\MyClass();
is not.
First code fragment works at staging but not at my local. Do I need to enable something at my local server?
Many thanks for help
Dynamic functions always require a fully-qualified namespace name and as such a leading
\would be redundant. That’s why you shouldn’t specify it:But still, it shouldn’t throw an error. Demo: http://codepad.viper-7.com/D8H19r