a way to fix the import issue

From: Date: Wed, 03 Oct 2007 19:46:41 +0000
Subject: a way to fix the import issue
Groups: php.internals 
Request: Send a blank email to internals+get-32609@lists.php.net to get a copy of this message
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

« previous php.internals (#32609) next »