A key theme in refactoring code is addressing issues within the internal structure of code while not altering the external behavior of the program being refactored. In some cases, this can mean introducing internal structure where it previously wasn't intentional or thought about before.
Refactoring as a process improves the design of code after it is written. While design is a critical phase of the software engineering process, it is often disregarded (not least in PHP); in addition to this, maintaining the structure of code over the long-term requires a continued understanding of the design of software. If a developer takes up a project without understanding how it was originally designed, they may develop upon it in a very crude fashion.
In Extreme Programming (XP), a phrase known as Refactor Mercilessly is used, it is self-explanatory. In XP, refactoring is proposed as a mechanism to keep software design as simple as possible and to avoid needless complexity. As is...