Re: [RFC] Access to aliases definition by reflection

From: Date: Mon, 13 Oct 2014 14:24:17 +0000
Subject: Re: [RFC] Access to aliases definition by reflection
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-77926@lists.php.net to get a copy of this message
On Mon, Oct 13, 2014 at 3:46 PM, Alexander Lisachenko < lisachenko.it@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

« previous php.internals (#77926) next »