Namespaces are actually just a form, and the ultimate goal is to refactor the code, but it's impossible to do this in a single pass.
At first, a pseudo proposition was given: thinkphp-based refactoring (not why). After a period of practice, it is found that this is a wrong way of thinking, in which the pits encountered in this slightly not table.
First, don't try to rewrite the whole namespace based on namespaces, but should be local.
The result of the final thinking is that the model layer is based on the transformation of the namespace, so that the model layer resources in the system can be reused under the new framework. Because the model layer in theory only deals with data, the least coupling.
But the transformation process also found some problems, the model layer coupled with business logic, even with the session, cache and other system environment, not purely DB operations, but contains a lot of business code, which means that this part of the code after the initial transformation is completed, it is not reusable in the new framework.
These problems also indirectly prove the correctness of some basic programming ideas: The essence of OOP is code reuse, the direct effect of the PSR Series specification to improve code reusability, the effect of code layering rationality on the maintainability of code, and the extreme negative effect of global variables on code reusability.
What is progressive refactoring?
The basic principle of progressive refactoring is compatibility, not overturning, as long as things become pushed to the back, it is not refactoring, is simply rewriting. In the entrepreneurial small team, pushed to rewrite, are u kidding me?
Compatibility is the starting point and process of refactoring, reuse is the result, new functionality can be developed based on a new framework, but you can reuse existing functional code, so this is a process.
The above describes the old PHP system based on the namespace refactoring experience, including the namespace, PHP content, I hope to be interested in PHP tutorial friends helpful.