#43183 [Asn->Csd]: "use" of the same class in difference scripts results in a fatal error

From: Date: Mon, 12 Nov 2007 15:52:32 +0000
Subject: #43183 [Asn->Csd]: "use" of the same class in difference scripts results in a fatal error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-119557@lists.php.net to get a copy of this message
ID: 43183 Updated by: dmitry@php.net Reported By: chagenbu@php.net -Status: Assigned +Status: Closed Bug Type: Scripting Engine problem Operating System: n/a (linux 2.6, mac os x 10.4) PHP Version: 5.3CVS-2007-11-03 (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-11-03 17:57:01] chagenbu@php.net Description: ------------ As per discussion on the PHP internals list, the proper way to ensure that when using a short name, the class loaded is always from the current namespace (even if it needs to be autoloaded and has not yet been loaded) is to import that class in every file where it is used. However, doing so in two separate scripts, OR just importing a class that has already been defined in the namespace, can result in a fatal error claiming an import clash. Because of the nature of namespaces and this bug it requires 2 small scripts to reproduce, not one. Reproduce code: --------------- ns_import1.php: --------------- <?php namespace Test; class Helper {} include dirname(__FILE__) . '/ns_import2.php'; ns_import2.php: --------------- <?php namespace Test; import Test::Helper; class Other {} Expected result: ---------------- No error, should be no output. Actual result: -------------- $ php ns_import1.php Fatal error: Import name 'Helper' conflicts with defined class in /tmp/ns_import2.php on line 5 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43183&edit=1

« previous php.bugs (#119557) next »