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.

PHP doesn't have a Reflection for that kind of object, however it can
be nice to add it to keep an information about namespace start
line/end line, file name, imported aliases and defined constants. And
add a getters for all other reflection classes, for example, (new
ReflectionClass('SomeClass'))->getReflecitonFileNamespace()->getAliases()

For PHP7 it can be extended more with AST parser information, for
example, add ReflectionSource class that can parse the source code and
build a reflection for that source. (new
ReflectionSource($fileContent))->getReflectionFileNamespaces()[0]->getAliases().
This patch will help a lot for tools that performs static analysis of
source code and provide a good API for userland extensions.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to