php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54438 use statement overwrite aliased namespace against using multiple
Submitted: 2011-04-01 10:09 UTC Modified: 2011-04-02 20:20 UTC
From: michal dot brzuchalski at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michal dot brzuchalski at gmail dot com
New email:
PHP Version: OS:

 

 [2011-04-01 10:09 UTC] michal dot brzuchalski at gmail dot com
Description:
------------
In use statement we can use "," to separate aliased namespaces but the alias only affect to the last one declared use namespace. It'll be logical to use all declared namespaces in alias and use classes/constants/closures/etc. from aliased namespace where they exists.

Test script:
---------------
<?

namespace A;
class test1 {}
class test2 {}

namespace B;
class test1 {}

use A, B as Foo;

$test1 = new Foo\test1;
echo get_class($test1). "\n";
$test2 = new Foo\test2;
echo get_class($test2). "\n";

Expected result:
----------------
B\test1
A\test2


Actual result:
--------------
B\test1
PHP Fatal error:  Class 'B\test2' not found in test.php on line 13


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-02 19:06 UTC] felipe@php.net
-Status: Open +Status: Bogus -Type: Bug +Type: Feature/Change Request
 [2011-04-02 19:06 UTC] felipe@php.net
This is not a bug. It works as expected, an alias cannot be used for more than one class/namespace/...
 [2011-04-02 20:11 UTC] michal dot brzuchalski at gmail dot com
So why there's no parse error if there can be more than one class/namespace aliased ?
 [2011-04-02 20:20 UTC] felipe@php.net
There is parser error, you just need to use the right code to reproduce it.

use A as Foo;
use B as Foo;

or

use A as Foo, B as Foo;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC