Bug #71983 [Nab]: Not clear namespace resolution
| From: | goetas at gmail dot com | Date: | Sat, 09 Apr 2016 12:04:49 +0000 |
| Subject: | Bug #71983 [Nab]: Not clear namespace resolution | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200455@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
User updated by: goetas at gmail dot com
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:
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?
Previous Comments:
------------------------------------------------------------------------
[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