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.
As for the leading \ for fully qualified identifiers, well it's a necessary
evil. As you said yourself PHP is PHP, and we have unique constraints to
meet, we have no scopes, we have no compile time packaging of the resources,
and since we don't have meta files describing the namespace resources (wink
wink...), we should stick to a single-rule no-ambiguity system.
For me the only way to make it clear to both humans and parsers alike is the
filepath semantics, in all places, including use. It's not perfect, there's
no completely problem-free solution, but "prepend \ for absolute path" is
able to become muscle memory, while other mixed solutions I've seen are more
confusing and require more thinking: "wait in this context what was what?".
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'
But this introduces a new keyword: nameof, which could clash with
function/class/constant "nameof" in existing source code. I could suggest
simply not having "nameof" and having direct assignment assign the class
name, but then we clash with constants which have the same name as the
class. So that's not doable either.
But it's definitely in-your-face issue while using namespaced code.
Regards, Stan Vassilev
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php