Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

If i've different version of same third-party library ( or class ) that have of course same namespaces and class names. Is there a way to include them in same project avoiding name collisions?

Another case for this issue happens when we've a modular project where components are developed separately . So we can have different modules that includes same external library file in their own folder, but of course when modules will be loaded , we have a class collision.

in this article Loading multiple versions of the same class

an user suggests to use this code:

namespace old {
   include /lib/api-1.0/library.php;
}
namespace foo {
   include /lib/api-2.0/library.php;
}

$oldlibary = new old\Library();
$newlibrary = new foo\Library();

but it doesn't work. Classes collides anyway.

So..is there another solution that is not hand-edit all the namespace of libraries to include?

thanks in advance

share|improve this question
the new is a keyword and it will not work like a namespace. – Trung-Hieu Le 32 mins ago
This is tricky because functions and classes are defined within the global scope once they are included. Variables are not. – Rainulf 28 mins ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.