开发者

How to use same named class in PHP without namespacing?

I have a problem, where I have two third party libraries classes that I have to extend and use together. But both have the same naming convention and two class name end up having 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 as the PHP vers开发者_JS百科ion is just 5.2.10 and not 5.3.

What options I have?


I think you can implement rpc like interface, for one class. For other you can extend and use. http://en.wikipedia.org/wiki/Remote_procedure_call


That's the trouble when you don't 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 that makes it clear which one is which.


This is exactly the problem that PHP namespaces are intended to solve. There is no clean way to do this pre-5.3. The best you can do is to rename one or both and go through the libraries correcting the calls. This is a pain, but, as they are separate libraries, this shouldn't be too difficult.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜