|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-15 21:05 UTC] phplists at stanvassilev dot com
Description:
------------
These two namespaces work as expected when in two separate files, and when
included together at runtime work as expected as well, but once they're merged
in the same file they result in a Fatal Error:
namespace Foo {
class Bar {}
}
namespace Foo {
use Bar;
}
Fatal error: Cannot use Bar as Bar because the name is already in use.
I understand this behavior was introduced with good intentions, but all it does
is break working code when files are merged together. The alternative namespace
construct was introduced specifically to support merging of multiple files
together without side effects, and this is such a side effect.
Expected result:
----------------
I expect that "use" statements should override default resolutions, and no Fatal
Error should be produced (the EXACT behavior we have right now when the above is
spread in two files which are required() at runtime).
Actual result:
--------------
Fatal Error when merging code.
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
The same problem arises when in a two namespace context. # File: App\N2\Foo.php namespace App\N2; use App\N1\Bar; class Foo { } # File: App\N2\Bar.php namespace App\N2; class Bar { } # File: App\N1\Bar.php namespace App\N1; class Bar { } Using Bar of App\N1 cause the same problem. I think that the use in App\N2\Foo.php should only be valid on the App\N2\Foo class context and not reflected on the entire namespace as the error message suggest.