Stan Vassilev | FM wrote:
>> Hi Marcin,
>>
>> Stan also requested this, so it should be considered as a possibility.
>>
>> Personally, I would rather not introduce this land mine. It requires
>> the user to do an implicit prepending of namespace name ("foo") to "bar"
>> in the use statement as well as a translation of "A", which could fast
>> lead to unreadable code.
>>
>> It is probably best to simply require a fully qualified name where it is
>> intended. Thus
>>
>> 1) require leading "\" in use statements
>> 2) allow "namespace\blah" in use statements, as this is a valid fully
>> qualified name.
>>
>> <?php
>> namespace my\ns;
>>
>> // this is a better way to do the suggested "use bar as A;"
>> use namespace\bar as A;
>> use \bar as B;
>>
>> class mine extends \my\parentclass {}
>> ?>
>
> Greg, I can't spot where does your example differ from what I and Marcin
> suggested? Please explain.
I would not allow "use blah\blah as bar;"
> And there's one more pain point which I posted earlier on the list
> about, but now as I prepare my framework for 5.3 namespaces, I *really*
> feel the pain in practice: the inability to pass a class/function name
> without specifying it fully as a string.
>
> My suggestion was: use foo\bar\baz as alias; $name = nameof alias;
> // $name == 'foo\bar\baz'
Are you aware of __NAMESPACE__? Also, if you are using a lot of
external namespace names, you might consider simply defining constants:
namespace foo\bar\baz;
const ns = __NAMESPACE__;
then you can simply do
use foo\bar\baz; $name = baz\ns;
I don't see a huge pressing need for nameof since the above is 3 extra
lines of code - total - per NS.
If this sounds good, I will add an example to the new docs
yet-to-be-committed.
Greg
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php