php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60135 Request for mechanism to resolve namespace from alias
Submitted: 2011-10-25 23:32 UTC Modified: 2017-03-11 17:54 UTC
Votes:7
Avg. Score:4.3 ± 1.4
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:2 (33.3%)
From: rev40oz at hotmail dot com Assigned: nikic (profile)
Status: Closed Package: Reflection related
PHP Version: 5.3.8 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rev40oz at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-10-25 23:32 UTC] rev40oz at hotmail dot com
Description:
------------
I would like to request a feature for namespacing in future versions.  From what 
I can tell, there is currently no way to resolve the full namespace from a 
namespace alias.  Something along the lines of:

namespace a\b\c as ABC;
echo resolve_namespace_alias(ABC); // prints 'a\b\c'

Situations where class names are passed by string (factories) and need full 
qualification can't currently benefit from NS aliasing in an elegant way.

Thanks,
Chuck Reed


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-11 17:54 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2017-03-11 17:54 UTC] nikic@php.net
I'm closing this as the primary use-case should be addressed by the ::class feature introduced in PHP 5.5. You can pass ABC::class to your factory and it will resolve to a class name string based on the class alias table.

Implementing a function such as resolve_namespace_alias() is not possible, because aliases are per-file -- aliases in the file where the factory is implemented and where it is used may be different.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC