Dynamic fully qualified namespaces - good or bad?
I'm quite new to namespaces though I am now sold on the idea and think they're excellent. My main gripe was though that the scope of a use statement was only in the file it was called. So, in my current project outside of the bootstrap file I have loads of fully qualified namespaces. E.g.
Not that it would happen often but if I renamed the Package to Package2 I would have to go through my code and rename \Vendor\Package\ to \Vendor\Package2\.
$object = new \Vendor\Package\Class($parameter);
I have just found out as of 5.3 (which I'm using) you can call classes through variables—including namespaces. So I guess I could do something like:
I'm interested to know if you think this is a good idea or not. My gut tells me to avoid this for readability but was interested to know if others were using this. Of course, if you ever renamed a class you'd be stuck updating everything anyway.
$package = '\Vendor\Package\\';
$currentPackage = $package . 'Class';
$object = new $currentPackage($parameter);