Stanislav Malyshev wrote:
>> namespace Foo;
>> import Exception;
>
> Once more, import with one-term argument is a no-op. And will stay so.
> That's why we have the warning.
>
>> I think that either import ::Exception needs to work, or import
>> Exception shouldn't issue a warning.
>
> We'll discuss this one. I wonder if anybody else feels a need for it?
One of the nice features of import is that we will be able to take older
code, plop a namespace declaration at the top of the file and a few
imports and without recoding anything have full access to class names,
i.e. refactoring class names without actually having to touch the code. 
As such, this may mean aliasing top-level classes to another name.  I
don't have a specific example off the top of my head, but I hope this
makes sense.
>> I think you need to envision working in a large team on a large
>> project here, but you may simply not see the need.
>
> I'd say if you have large team which has a possibility of having
> classes with same names running into each other, why not having them
> reside in different namespaces?
After some reflection, I think the only use case would be in an autoload
implementation.  If an unknown class is simply used, the executor
assumes you want the current namespace.  The only way around this is to
do something like "import Classname as Classname;" which seems kind of
silly.

Another possibility for all of this would be to have "use" trigger
autoload if the class doesn't exist, as a runtime option.  "import"
could be a non-autoloading version of the same thing.  i.e.:

<?php
namespace Blah;
use Burp::Exception;
use Burp::thing as mine;
import Burp::another;

$b = new Exception; // Burp::Exception
$c = new mine; // Burp::thing
$a = new another; // Burp::another
?>

would trigger autoload for Burp::Exception and Burp::thing and fatal
error if the class can't be loaded, and simply alias "Burp::another" to
"another" in the script.  This may be too much, I'm on the fence on its
utility, but it would provide a more abstract way of triggering a
friendly error message if a class is not found, something like "class
Burp::Exception was not found, and could not be autoloaded
(include_path=".:/whatever")".

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to