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

php

Solution

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.

Problem

I'm using PHP 5.4, and have a PSR-0 class structure similar to the following. A\Library\Session.php: ``` namespace A\Library; class Session { ... } ``` My\Application\Session.php: ``` namespace My\Application; class Session { ... } ``` My\Application\Facebook.php: ``` namespace My\Application; use A\Library\Session; class Facebook { ... } ``` When I try to run the application, I get the following error: Cannot use A\Library\Session as Session because the name is already in use in My\Application\Facebook.php Even though it's not, at least not in this file. The Facebook.php file declares only the `Facebook` class, and imports exactly one `Session` class, the `A\Library` one. 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. Am I wrong (in that case please point to the relevant documentation), or is this a bug?

Original source