RE: [PHP-DEV] a way to fix the import issue
| From: | Dmitry Stogov | Date: | Thu, 04 Oct 2007 07:35:25 +0000 |
| Subject: | RE: [PHP-DEV] a way to fix the import issue | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-32628@lists.php.net to get a copy of this message | ||
In your example :
<?php
namespace Foo;
import Blah::Exception;
$a = new Exception;
?>
"new Exception" refer to "Blah::Exception" and will fail if such class
doesn't exists.
"import Blah::Exception" creates an alias with short name "Exception" only
for current file (it doesn't creates "Foo::Exception")
May be I didn't understood the question. :)
Thanks. Dmitry.
> -----Original Message-----
> From: Stanislav Malyshev [mailto:stas@zend.com]
> Sent: Thursday, October 04, 2007 12:50 AM
> To: Greg Beaver; Dmitry Stogov
> Cc: php-dev; Benjamin Schulz
> Subject: Re: [PHP-DEV] a way to fix the import issue
>
>
> > <?php
> > namespace Foo;
> > import Blah::Exception;
> > $a = new Exception;
> > ?>
> >
> > should in fact be implicitly importing Blah::Exception as
> if it were
> > Foo::Exception, rather than as ::Exception. In other
> words, I would
> > actually expect the above code to be equivalent to:
> >
> > <?php
> > namespace Foo;
> > import Blah::Exception as Foo::Exception;
> > $a = new Foo::Exception;
> > ?>
>
> No, not really. It's equivalent to:
> <?
> $a = new Blah::Exception();
> ?>
>
> There's no class named Foo::Exception and import does not create it.
> However, I think I see what you were meaning - that new
> Exception should
> refer to Blah::Exception. I think it is true. Dmitry, could you look
> into it? I.e. unqualified lookups inside namespace should also take
> imports into account.
>
> --
> Stanislav Malyshev, Zend Software Architect
> stas@zend.com http://www.zend.com/
> (408)253-8829 MSN: stas@zend.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>