How to use the same named class in PHP without namespace?

I have a problem when I have two classes of third-party libraries that I have to distribute and use together. But both have the same naming convention, and two class names have the same name.

Since I cannot extend two classes, I don’t know how to fix them, how to create a wrapper against one. I cannot use PHP namespaces since the PHP version is just 5.2.10, not 5.3.

What options do I have?

+3
source share
3 answers

I think you can implement an rpc interface for one class. For others, you can expand and use. http://en.wikipedia.org/wiki/Remote_procedure_call

+1
source

This is a problem when you do not have namespaces.

The only option you have is to go through the code of one or the other and change all the class names. Perhaps add a prefix to both of them, which makes it clear which one.

+1
source

This is exactly the problem that PHP namespaces are designed to solve. There is no clean way to do this until 5.3. The best you can do is rename one or both and go through libraries that fix the calls. This is a pain, but since they are separate libraries, it should not be too complicated.

My other suggestion is to make sure that installing 5.3 is really impossible. This is by far the best solution to your problem.

+1
source

Source: https://habr.com/ru/post/1479857/


All Articles