On 31 October 2014 10:27, Miloslav Hůla <miloslav.h...@gmail.com> wrote:

> Dne 30.10.2014 14:50, Levi Morrison napsal(a):
>
>> I also don't think this feature is needed. In comments, simply use
>> fully qualified names.
>>
>
> FQN can be used in docblocks, that's true. But if you write some library
> which uses annotations and you want to offer a kind of comfort to your
> users, your hands are tied. You force them to use FQN.
>
> Personaly, I don't like any code/information duplication. Using FQN when
> the alias is already defined is wrong.
>
> And generally, there is no way how to get defined aliases in current PHP.
>
>  Additionally, I really don't see how these are related to each other:
>>
>>      use Library\Http;
>>
>>      class C {}
>>
>>      $rc = new ReflectionClass('c');
>>
>>      var_dump($rc->getDefinedAliases());
>>      /*
>>      array(1) {
>>       ["http"] => string(12) "Library\Http"
>>      }
>>      */
>>
>> How is ReflectionClass C related to `Library\HTTP` at all?
>>
>
> This example from RFC shows scope of defined aliases only.
>
> On the beginning, I was thinking where to place the "access point" to
> aliases definition. When I realized, that alias can be defined anywhere
> except a class or function body, ReflectionClass and ReflectionFunction
> looks like right place.
>
> The relation is more obvious in following example:
>
> use Library\Http;
>
> class C
> {
>         /** @var Http\Clients\CurlClient */
>         public $client;
> }
>
>
> -- Milo
>

I agree with Levi, this doesn't make a lot of sense. The only thing that
would make sense in terms of supporting aliases for me would be this:

<?php

use Library\Http\Clients\CurlClient as HttpClient;

$rc = new \ReflectionClass('HttpClient');
var_dump($rc->getName()); // string(31) "Library\Http\Clients\CurlClient"

I cannot see the value in being able to inspect the compile time constructs
at run time, but I can see the value in being able to *use* them in strings
at run time.

However, even support for this doesn't make a lot of sense without also
supporting them everywhere else that strings can be used in place of a
class name literal, for example both of these cases would need to work as
well:

$className = "HttpClient";
$obj = new $className;
var_dump($obj instanceof $className);

There may be others as well, these are just two that immediately sprang to
mind.

The getDefinedAliases() code depicted above doesn't really belong on a
ReflectionClass, or any of the other classes that currently exist, as the
aliases aren't associated with the class/function itself but the
environment in which it was defined.

Thanks, Chris

Reply via email to