#42859 [Asn->Csd]: import always conflicts with internal classes

From: Date: Wed, 17 Oct 2007 10:01:50 +0000
Subject: #42859 [Asn->Csd]: import always conflicts with internal classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118624@lists.php.net to get a copy of this message
ID: 42859 Updated by: dmitry@php.net Reported By: greg at chiaraquartet dot net -Status: Assigned +Status: Closed Bug Type: Scripting Engine problem Operating System: linux PHP Version: 5CVS-2007-10-05 (CVS) Assigned To: dmitry New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-10-17 09:59:43] dmitry@php.net The patches are completely right, however I'll optimize them a little bit. Thank you for catching and fixing this issue. ------------------------------------------------------------------------ [2007-10-05 14:26:52] cellog@php.net both patches were missing a zend_str_tolower call, I've updated them to include this ------------------------------------------------------------------------ [2007-10-05 06:56:13] dmitry@php.net Patch seems to be proper. I'll review and commit it later. ------------------------------------------------------------------------ [2007-10-05 02:16:15] cellog@php.net accidentally didn't log in as cellog to submit this. ------------------------------------------------------------------------ [2007-10-05 02:03:44] greg at chiaraquartet dot net Description: ------------ zend_do_import incorrectly compares an import name to global class names. It should compare EG(current_namespace) . '::' . importname to check for conflicting names. This is because when inside a namespace, to the user, import should behave in the same manner as a class declaration. This code: <?php namespace Foo; class Exception {} ?> creates Foo::Exception. This code: <?php namespace Foo; import Blah::Exception as Exception; ?> Should essentially work as if the user had typed: <?php namespace Foo; import Blah::Exception as Foo::Exception; ?> In other words, it should resolve future uses of "Exception" to "Blah::Exception" and "::Exception" to "Exception" and not complain about "Exception" conflicting with "::Exception" Patch for PHP 5: http://pear.php.net/~greg/fix_import.patch.txt Patch for PHP 6: http://pear.php.net/~greg/fix_import.php6.patch.txt Reproduce code: --------------- testme.php: <?php namespace Blah; class Exception extends ::Exception {} ?> test.php: <?php namespace Foo; include 'testme.php'; import Blah::Exception; $a = new Exception; throw $a; ?> Expected result: ---------------- Fatal error: Uncaught exception 'Blah::Exception' in /home/cellog/workspace/php5/test.php:5 Stack trace: #0 {main} thrown in /home/cellog/workspace/php5/test.php on line 5 Actual result: -------------- Fatal error: Import name 'Exception' conflicts with defined class in /home/cellog/workspace/php5/test.php on line 4 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42859&edit=1

« previous php.bugs (#118624) next »