Whats the frequency of the letter d in:
Q: How do I partially add PHP namespacing to a library without breaking existing code? My company has created a modular PHP framework over the years, beginning long before PHP 5.3 added namespaces. Recently, we decided to start using namespaces in our librarys new code, and we intend to namespace old code eventually. However, we have a few issues we are trying to work out to determine if adding namespaces to a pre-v5.3 codebase is just not a good idea:


*

*Can I namespace a class but also import (use) the global namespace so all global classes do not need a \ prefix?

*If we namespace an existing class in our library, how can we prevent all existing projects from breaking as soon as the framework upgrades? For example, can the library change the name of class ThemeEngine to \module\theme\ThemeEngine, but the existing websites call ThemeEngine without any code modification? If so, what would that code look like?


A: *

*You cant use namespaces at all, sadly, only classes: http://www.php.net/manual/en/language.namespaces.importing.php.
Edit: You can import classes from the global namespace, like they did with the ArrayObject in one of the examples.

*You could have a global section of use statements so that all pre-existing classes, which are in the global namespace as well, theoretically should find the classes just fine. Theoretically...
We are in the same boat as you, sort of. We have some old code that doesnt use namespaces, but does use the _ namespace faker (like Zend_Db_Table...) and we have some older code that doesnt even fake namespaces. Were probably going to take the same route, but we still need to test if its possible at all. Good luck!

A: Yea what I did in the end was use - use to import the individual classes that I needed
for example instead of adding / in front of everything like:
\DateTime()

I added under my namespace
namespace MyProject;
use DateTime;

...
DateTime();     //without \
...


user
The text includes 67 "d"s in total.
assistant