Cannot use X as Y because the name is already in use, even though it's not

There is a bug confirmed in PHP that may affect the behavior you see. It is supposed to fatal error, but with opcache enabled, it may still execute flawlessly.

https://bugs.php.net/bug.php?id=66773

If it still concerns you, please vote for the bug.


No, this is not a bug. As mentioned in Using namespaces: Aliasing/Importing

use A\Library\Session;

is the same as:

use A\Library\Session as Session;

So try using something like:

use A\Library\Session as AnotherSessionClassName;

The only problem I can see is that another Session class exists in the same namespace as the Facebook class, but as it was never imported in the Facebook.php file, I thought it did not matter at all.

Yes, it does matter. This is why you don't need to "import" classes from the same namespace. If you have conflicting names from different namespaces, you need to alias the class.

namespace My\Application;
use A\Library\Session as ASession; // choose a proper alias name here

class Facebook { ... }

Tags:

Php