On Mon, Oct 13, 2014 at 3:46 PM, Alexander Lisachenko < lisachenko...@gmail.com> wrote:
> Hello! > > > I've written an RFC which proposes to expose a namespace aliases/imports > for > > user-land code. > > > > https://wiki.php.net/rfc/aliases_by_reflection > > I think that this idea is good, however it isn't correct to keep > aliases per each class, because they are applied per scope. > TokenReflection library uses ReflectionFileNamespace for that to > define a namespace section in the file (there can be many namespaces > per one file) and provides an API to fetch aliases. It also provides > extended classes with link to the ReflectionFileNamespace. > While good coding style dictates that namespace imports happen at the top of the file, PHP itself places no such restrictions. In particular the following is perfectly valid code: class A {} use Foo\Bar; class B {} Here the declared aliases will be different for classes A and B. This is the reason why the aliases are exposed per-class and per-function. Nikita