Bug #71983 [Nab]: Not clear namespace resolution

From: Date: Sat, 09 Apr 2016 14:24:32 +0000
Subject: Bug #71983 [Nab]: Not clear namespace resolution
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200456@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71983&edit=1 ID: 71983 Updated by: cmb@php.net Reported by: goetas at gmail dot com Summary: Not clear namespace resolution Status: Not a bug Type: Bug Package: *General Issues PHP Version: 5.6.20 Assigned To: cmb Block user comment: N Private report: N New Comment: > Buy the documentation says that aliases are per file. But now it > seems that they are per namespace. Is it? You're probably referring to [1]: > Importing rules are per file basis, meaning included files will > NOT inherit the parent file's importing rules. And indeed, that is so. However, if you are importing a class inside a namespace (as in your supplied test script), there must not already be another class with the same name in that namespace. For further information on this issue, please ask on php-general@lists.php.net. [1] <http://php.net/manual/en/language.namespaces.importing.php#language.namespaces.importing.scope> Previous Comments: ------------------------------------------------------------------------ [2016-04-09 12:04:49] goetas at gmail dot com Ok, Thanks. It is clear now. Buy the documentation says that aliases are per file. But now it seems that they are per namespace. Is it? ------------------------------------------------------------------------ [2016-04-09 11:25:58] cmb@php.net The second namespace declaration already defines a class C in namespace B, hence the error. You'd have to alias A\C, see <https://3v4l.org/g90NX>, for instance. ------------------------------------------------------------------------ [2016-04-07 16:03:56] goetas at gmail dot com Description: ------------ It is not possible to alias a class from a namespace. I have also tried placing classes in different files, but the problem persists. Test script: --------------- <?php namespace A { class C { } } namespace B { class C { } } namespace B { use A\C; echo "something"; } Expected result: ---------------- something Actual result: -------------- PHP Fatal error: Cannot use A\C as C because the name is already in use in /vagrant/A/run.php on line 12 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71983&edit=1

« previous php.bugs (#200456) next »