Re: Feature proposal: userland support for name qualification
| From: | Ferenc Kovacs | Date: | Sat, 31 Jul 2010 14:17:11 +0000 |
| Subject: | Re: Feature proposal: userland support for name qualification | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49192@lists.php.net to get a copy of this message | ||
On Sat, Jul 31, 2010 at 2:14 PM, Ignas Rudaitis
<ignas.rudaitis@gmail.com> wrote:
> Hello php.internals,
>
> Here is a (hopefully) simple language feature I'd like to suggest:
>
> Now that PHP has support for namespaces and therefore makes it
> possible to refer to classes, functions and constants by their shorter
> unqualified aliases, it would be useful to extend this functionality
> to string references to these classes/functions/constants as well.
> Perhaps it wouldn't be as useful for constants, but class and function
> names need to be used as string literals from time to time, so given
> that a statement like "use Foo\Bar\Baz" is present, having a special
> syntax for retrieving the fully qualified name as a string, like
> Baz::__CLASS__, qualify(Baz) or use(Baz) would save numerous
> keystrokes, eliminate possible typos and make refactoring (renaming)
> easier.
>
> The use cases that come to my mind are class names in exception
> messages, in DI container setup code, also things like Doctrine's
> $entityManager->getRepository('Application\Entities\Message') and
> callable function name strings.
>
> Of course, if it's actually problematic to implement this, that's
> fine, just let me know.
>
> Thanks.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi.
I think that this could be a good feature.
You can get the qualified name with get_class() if you have an
instant, or with __CLASS__ in your class methods, but you can't
explicitly convert an unqualified name into qualified.
However this wasn't a big problem for me, because every reference is
used as a fully qualified name, so I never had to convert between
them.
But this could be a good addition to the namespace features.
Tyrael