# a way to fix the import issue

- Thread: https://externals.io/message/32609
- Original archive: https://news-web.php.net/php.internals/32609
- Started by Greg Beaver on 2007-10-03T19:46:41+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #32609 — Greg Beaver — 2007-10-03T19:46:41+00:00

URL: https://externals.io/message/32609#32609

Hi all,

Benjamin has in fact unearthed a bug in the implementation of import.
This code:

<?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;
?>

This is a simple fix.
http://lxr.php.net/source/ZendEngine2/zend_compile.c#5122 should be
using zend_do_build_namespace_name() with CG(current_namespace) to
retrieve the actual classname to import, rather than just the last part
after ::.  With this change, the example code above would work without
conflicting with either the built-in exception or Foo::Exception unless
Foo::Exception is included from another file, which would give the
correct error.

I'm afraid I don't have time for a proper patch right now, but it is a
very simple fix, we would just need to add a few lines to put the
classname zval and CG(current_namespace) into znodes and pass to
zend_do_build_namespace_name(), then extract the created zval for name.

Greg

---

## #32617 — Stanislav Malyshev — 2007-10-03T20:49:50+00:00

URL: https://externals.io/message/32609#32617 · In reply to: #32609

> <?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
