Can I put namespace in old classes?

Asked

Viewed 33 times

3

Good people, I work in a company that has a huge system, and we used the Doctrine to do the Mapping of our tables, however this is very old we used the Doctrine a long time and at the time we had no knowledge of namespaces.

Nowadays if I put only the namespace in all DAO classes to use on the whole system with the help of Poser’s PSR4 autoload it would give some error in the system, or it would work normal ?

  • 1

    No problem at all, Voce can put themselves after, they exist precisely to avoid conflicts between variables with the same name.

1 answer

2


As you may already know and as already described in the commentary of this question namespaces is intended to avoid name conflicts. Such conflicts may occur in relation to the names of:

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

As you mentioned your project legacy currently does not use namespaces and works perfectly. This means that there are no name conflicts in the cases cited above.

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

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

  • I want to implement dependency injection so I really need to put namespaces in the classes.

  • 1

    @Lucaslima without problems. The namespaces will be of great help. I believe I already have the knowledge of how to apply addiction injection, but as knowledge is never enough, recently posted an answer on addiction injection

  • 1

    A change like that, even more by tinkering with legacy systems, sure that problems have appeared, but nothing that can’t be dealt with. What you want to do is possible and viable.

  • Yes I already have the knowledge about dependency injection and I’ll give a read on your post, all information is welcome, the system has more than 10 years, I hope it works out all right !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.