php – Can I namespace old classes?


Well folks, I work in a company that has a huge system, and we use Doctrine to do the mapping of our tables, but this is very old, we used Doctrine for a long time and at that time we didn't know about namespaces.

Nowadays if I just put the namespace in all DAO classes to use in the whole system with the help of composer PSR4 autoload would it give some error in the system, or would it work normally?


As you may already know and as described in the comment to this question, namespaces are intended to avoid name conflicts. Such conflicts can occur regarding the names of:

  1. Classes;
  2. Functions;
  3. Variables; and
  4. Constants.

As you mentioned your legacy project at the moment doesn't use namespaces and works perfectly. This means that there are no name conflicts in the cases mentioned above.

Before making this change there is only one requirement. Your PHP version should be >= 5.3.0 .

If this is ok, there will be no objection. This change will only benefit the maintenance of the system as a whole. Great decision.

Scroll to Top