Re: Re: namespaces: import name conflicts with defined class
| From: | Gregory Beaver | Date: | Wed, 03 Oct 2007 14:00:45 +0000 |
| Subject: | Re: Re: namespaces: import name conflicts with defined class | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32589@lists.php.net to get a copy of this message | ||
Benjamin Schulz wrote:
> On 02.10.2007, at 22:04, Stanislav Malyshev wrote:
>
>
>>> <?php
>>> import ::Exception as Notused;
>>> import Foo::Exception;
>>> ?>
>>>
>>
>> I wouldn't actually recommend using such code. If you have
>> Foo::Exception just use Foo::Exception - it's short enough :)
>>
>
> And what if not? "throw App::package::subpackage::Exception" in a file
> that has the namespace "App::package::subpackage" is just wrong,
> importing the Exception as a different name as well. Importing the
> global Exception as something else - i don't even know what to answer to
> that ... this problem makes the whole concept just seem broken, is there
> even a concept? ;)
>
> regards,
> Benjamin
<?php
namespace test;
class Exception {}
$a = new Exception('hi');
?>
The above code works just fine.
Yes there is a concept. import is best used within a namespace. So,
namespace your code and there is no need to import global classes.
Greg